VBA - Len


Advertisements

The Len function returns the length of the given input string including the blank spaces.

Syntax

Len(String)

Example

Add a button and add the following function.

Private Sub Constant_demo_Click()
   Dim var1 as Variant
   Dim var2 as Variant
   
   var1 ="Microsoft VBScript"
   msgbox("Length of var1 is : " & Len(var1))
  
   var2 =       "       Microsoft VBScript           "
   msgbox ("Length of var2 is : " & Len(var2))
End Sub

When you execute the above function, it produces the following output.

Length of var1 is : 18
Length of var2 is : 36
vba_strings.htm
Advertisements