TOP

VBA Function: Left

YouLibreCalc for Excel logo

Description

The VBA LEFT Function returns the specified number of characters of a string from the left.


LEFT Syntax

Left(text, number_characters)

VBA Left Example

Retrieve a variable number of characters from the same string from the left:

Sub LeftExample()
    
     MsgBox Left("www.moonexcel.com.ua", 1)  'Returns: w
     MsgBox Left("www.moonexcel.com.ua", 2)  'Returns: ww
     MsgBox Left("www.moonexcel.com.ua", 3)  'Returns: www
     MsgBox Left("www.moonexcel.com.ua", 4)  'Returns: www.
     MsgBox Left("www.moonexcel.com.ua", 5)  'Returns: www.m
     MsgBox Left("www.moonexcel.com.ua", 10) 'Returns: www.moonex
     MsgBox Left("www.moonexcel.com.ua", 50) 'Returns: www.moonexcel.com.ua

End Sub
The function that returns the specified number of characters from the right is the RIGHT function.
To extract characters inside a string, you can use the MID function.