Len(string)
対象文字(引数:string)の文字数を返す関数です。
引数:stringに変数を使用する場合は文字列型であるstringにしないと 変数の型の文字数を返してしまい違う値になります。
例
↑のようにlong、doubleの型を宣言した変数の場合はそれぞれ4(long),8(double)と返してしまっています。
対象文字(引数:string)の文字数を返す関数です。
引数:stringに変数を使用する場合は文字列型であるstringにしないと 変数の型の文字数を返してしまい違う値になります。
例
Sub SampleLen()
Dim a As String
Dim b As String
Dim c, d As Long, e As Double
'変数に値を入れる
a = Cells(2, 2) 'aaa(string)
b = Cells(3, 2) '123(string)
c = Cells(4, 2) '123(variant)
d = Cells(5, 2) '123(long)
e = Cells(6, 2) '123(double)
'3列目に文字数を返す
Cells(2, 3) = Len(a)
Cells(3, 3) = Len(b)
Cells(4, 3) = Len(c)
Cells(5, 3) = Len(d)
Cells(6, 3) = Len(e)
End Sub
↑のようにlong、doubleの型を宣言した変数の場合はそれぞれ4(long),8(double)と返してしまっています。