The VBA LEN function is listed under the text category of VBA functions. When you use it in a VBA code, it returns the number of characters in a string. In simple words, you can count the number of characters of a string. It works like the LEN function in the worksheet.
- Expression: The expression for which you want to count the characters.
To practically understand how to use VBA LEN function, you need to go through the below example where we have written a vba code by using it:
Sub example_LEN() Range("B1").Value = Len(Range("A1")) End Sub
In the above code, we have used the LEN to count the number of characters from the cell A1 (Excel Champs) and in the result, it has returned 12 in the result as the value “Excel Champs” has 12 characters including the space between the words.
- If the supplied string is NULL it will return NULL in the result.