VBA Left function

Left Function Description

The VBA Left function extracts a substring from a string, starting with the left-most character.

Use the Right function to extract characters from the right hand side of the string. Use the Mid function to get a substring from the middle of any string (looking from the left).

Syntax

The syntax for the Left function in VBA is:

Left( text, length )

Parameters

text
The string that you wish to extract from.

length
It indicates the number of characters to extract, starting from the left-most character.

Other Notes

The Left function can well be superseded by the Mid function e.g. the following will provide identical results.

Left( text, length)

Mid( text, 1, length)

The string index position in the Mid, Left and Right functions starts at 1.

For better performance use the typed version of the Left function: Left$ instead of the default Left. This is because the Left function return a variant instead of a string as therefore impacts performance. For more information on VBA Performanceread here

Example usage

The Left function can be used in VBA code. Let’s look at some VBA Left function examples:

Left "Hello", 4
'Result: "Hell"

Left "Hello", 10
'Result: "Hello"