The VBA Len function returns the number of characters in a supplied string or the number of bytes required to store a supplied variable.
The syntax of the VBA Len function is:
Where the Expression argument is the string or variable that you require the length of.
' Example 1. Find the length of the string "John Michael Smith".
Dim strLen As Integer
' The variable strLen is now equal to 18.
strLen = Len( "John Michael Smith" ) |
In the example above, the VBA Len function returns the result 18.
' Example 2. Return the length of an empty string "".
Dim strLen As Integer
' The variable strLen is now equal to 0.
strLen = Len( "" ) |
In the example above, the VBA Len function returns the value 0.
Further details and examples of the VBA Len function are provided on the Microsoft Developer Network.