LEFT(string, length)

Returns a number of characters from the left of a string (Variant / String).


stringThe text string (String).
lengthThe number of characters to return (Long).

REMARKS
* If "string" is Null, then Null is returned.
* If "length" = 0, then a zero length string ("") is returned.
* If "length" = > Len("string"), then "string" is returned.
* To determine the number of characters in string, use the LEN function.
* You can use the RIGHT function to return a number of characters from the right of a string.
* You can use the INSTR function to return the position of a substring within a larger string, starting at the beginning.
* You can use the LEN function to return the number of characters in a string.
* You can use the LEFTB function to be used with byte data.
* You can use the LEFT$ function to return a String data type instead of a Variant data type.
* You can use the LEFTB$ function to return a String data type instead of a Variant data type.
* The equivalent Excel function is Application.WorksheetFunction.LEFT
* The equivalent .NET function is Microsoft.VisualBasic.Strings.Left
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print Left("sometext", 4)               '= "some"  
Debug.Print Left("sometext", 20) '= "sometext"
Debug.Print Left("", 6) '= ""

Dim sResult As String
sResult = Left("bettersolutions", 6)
Debug.Print sResult '= "better"

Dim sText As String
sText = "bettersolutions.com"
sResult = Left(sText, Len(sText - 4)) 'remove the last 4 characters
Debug.Print sResult '= "bettersolutions"

sText = "better solutions com"
sResult = Left(sText, InStr(sText, " ") + 1) 'returns the first word
Debug.Print sResult '= "better"

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited Top