VBA Len function

The VBA Len function returns the character length of a specified string i.e. the VBA String length, assuming that the length of an empty String “” is 0.

VBA Len Syntax

The syntax for the Len function in VBA is:
function examples:

 Len( text )

Parameters

text
The string for which the character length is to be returned for.

Example usage to get VBA String length

The Len function can be used in VBA code to get the length of VBA Strings. Let’s look at some VBA Len function examples:

 
Len "Hello" 'Result: 5

Len "Hi There!" 'Result: 9

Len "" 'Result: 0

Speaking to the last example it is best to use the VBA constant vbNullString instead of it’s equivalent for best performance.

 
Len "" 'Result: 0

Len vbNullString 'Result: 0