La funzione LEN VBA restituisce il numero di caratteri in una stringa.
Len(testo)
Ottieni il conteggio dei caratteri di più righe:
Sub LenExample1()
MsgBox Len("") 'Restituzioni: 0
MsgBox Len("45") 'Ritorni: 2
MsgBox Len("excel") 'Ritorni: 5
MsgBox Len("www.moonexcel.com.ua") 'Ritorni: 20
variable = "moonexcel"
MsgBox Len(variable) 'Ritorni: 9
End Sub
Utilizzando la funzione Len in condizioni che verificano che il nome utente contenga almeno 3 caratteri prima di eseguire l'azione:
Sub LenExample2()
name = InputBox("Inserire username:", "Nome")
If Len(name) >= 3 Then
MsgBox "Ben fatto" & name & "!"
End If
End Sub