How to Remove Characters from Left/Right of String in Excel VBA?

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
How to Remove Characters from Left/Right of String in Excel VBA?

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.

How to Remove Characters from Left/Right of String in Excel VBA?

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this article, you will learn about the SKEW.P function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the SKEW function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the RANK.EQ function, the formula syntax and usage of the function in Microsoft...
  • Excel
  • November 23, 2021