VBA LEN 関数は、文字列内の文字数を返します。
Len(テキスト)
複数行の文字数を取得します。
Sub LenExample1()
MsgBox Len("") '戻り値: 0
MsgBox Len("45") '戻り値: 2
MsgBox Len("excel") '戻り値: 5
MsgBox Len("www.moonexcel.com.ua") '戻り値: 20
variable = "moonexcel"
MsgBox Len(variable) '戻り値: 9
End Sub
アクションを実行する前にユーザー名に少なくとも 3 文字が含まれていることを確認する条件で Len 関数を使用します。
Sub LenExample2()
name = InputBox("ユーザーネームを入力してください:", "名前")
If Len(name) >= 3 Then
MsgBox "素晴らしい" & name & "!"
End If
End Sub