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 post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...