VBA Function: Left
The VBA Left function returns a specified number of characters from the left of a string.
Usage:
Left(text, num_chars)
Example of Usage
Using the Left function to retrieve a variable number of characters from the left of a string:
Sub example()
MsgBox Left("www.excel-pratique.com", 1) 'Returns: w
MsgBox Left("www.excel-pratique.com", 2) 'Returns: ww
MsgBox Left("www.excel-pratique.com", 3) 'Returns: www
MsgBox Left("www.excel-pratique.com", 4) 'Returns: www.
MsgBox Left("www.excel-pratique.com", 5) 'Returns: www.e
MsgBox Left("www.excel-pratique.com", 10) 'Returns: www.excel-
MsgBox Left("www.excel-pratique.com", 50) 'Returns: www.excel-pratique.com
End Sub
The function that returns a specified number of characters from the right is the Right function.
To extract characters from within a string, you can use the Mid function.