MS Excel: LEFT Function (WS, VBA)
In Microsoft Excel, the LEFT function allows you to extract a substring from a string, starting from the left-most character.
The syntax for the LEFT function is:
LEFT( text, [number_of_characters] )
text is the string that you wish to extract from.
number_of_characters is optional. It indicates the number of characters that you wish to extract starting from the left-most character. If this parameter is omitted, only 1 character is returned.
- Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Function
- Worksheet function (WS)
- VBA function (VBA)
Worksheet Function Example
Let's take a look at an example to see how you would use the LEFT function in a worksheet:
Based on the Excel spreadsheet above, the LEFT function would return the following:
|=LEFT(A1, 5)||would return "Alpha"|
|=LEFT(A2, 8)||would return "techonth"|
|=LEFT("Excel", 2)||would return "Ex"|
|=LEFT("Excel")||would return "E"|
|=LEFT("Excel", 25)||would return "Excel"|
VBA Function Example
The LEFT function can also be used in VBA code. For example:
Dim LResult As String LResult = Left("Alphabet",3)
The variable LResult would now contain the value of "Alp".