There are times when you know the length of the string but want to remove the characters from left or right side of it using VBA in Excel. You can use the functions RIGHT and LEFT to achieve this.
RIGHT function in Excel VBA
Assume that you have a string of 8 characters and you want to remove 1 character from the left side of the string and return 7 characters from it, you can use the RIGHT function as shown below.
Sub GetString() Dim str1 As String str1 = "isenthil" MsgBox Right(str1, 7) End Sub
LEFT function in Excel VBA
Assume that you want to remove 1 character from the right side of the same string, you can use the below code snippet.
Sub GetString() Dim str1 As String str1 = "isenthil" MsgBox Left(str1, 7) End Sub
Note : This doesnot work for a variable length text. If you want to use the Right/ Left function with a variable length string, you should be using the LEN function to calculate the length that you want t return.