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.
- Str: The string from which you want to extract a substring.
- Length: The integer to specify the length of the substring.
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.