How to use the VBA LEFT Function (Syntax + Example)

HomeVBA Functions LIST (Category Wise)How to use the VBA LEFT Function (Syntax + Example)

The VBA LEFT function is listed under the text category of VBA functions. When you use it in a VBA code, it returns a sub-string from a string from the starting position. In simple words, you can extract a number of characters from a string from its starting (which is the left side). It simply works like the LEFT function in the worksheet.

Syntax

Left(Str, Length)

Arguments

  • Str: The string from which you want to extract a substring.
  • Length: The integer to specify the length of the substring.

Example

To practically understand how to use VBA LEFT function, you need to go through the below example where we have written a vba code by using it:

Sub example_LEFT()
Range("B1").Value = Left(Range("A1"), 5)    
End Sub

In the above code, we have used LEFT to get the 5 characters from the left side of the cell A1 (Excel Champs) and get it in the cell B1. It has returned the value (Excel) in the result as these are the first 5 characters we have in the cell A1.

Related Functions

FORMAT | INSTR | INSTRREV | LCASE | | LEN | LTRIM | MID | REPLACE | RIGHT | RTRIM | SPACE | STRCOMP | STRCONV | STRING | STRREVERSE | TRIM | UCASE