How will you remove first character from string using VBA?

Using the VBA code, we can remove the first character from a string by using the Mid function. The Mid function takes 3 parameters: the string, the starting position of the character to be removed and the number of characters to be removed. The starting position is always 1 for the first character and the number of characters to be removed is always 1. The returned value is the string without the first character. Therefore, to remove the first character from a string, we can use the code: Mid(string, 1, 1).


You can use the following basic syntax to remove the first character from a string using VBA:

Sub RemoveFirstChar()

    Dim i As Integer
    Dim myString As String

    For i = 2 To 11
    myString = Range("A" & i)
    Range("B" & i) = Right(myString, Len(myString) - 1)
    Next i
    
End Sub

This particular example removes the first character from each string in the range A2:A11 and outputs the results in the range B2:B11.

The following example shows how to use this syntax in practice.

Related:

Example: Using VBA to Remove First Character from Strings

Suppose we have the following list of basketball team names in Excel:

Suppose we would like to remove the first character from each team name.

We can create the following macro to do so:

Sub RemoveFirstChar()

    Dim i As Integer
    Dim myString As String

    For i = 2 To 11
    myString = Range("A" & i)
    Range("B" & i) = Right(myString, Len(myString) - 1)
    Next i
    
End Sub

When we run this macro, we receive the following output:

VBA remove first character from string

Column B displays each of the strings in column A with the first character removed.

If you would instead like to remove the first n characters from a string, simply change the 1 in the Right method to a different number.

For example, we can create the following macro to remove the first 2 characters from a string:

Sub RemoveFirstTwoChar()

    Dim i As Integer
    Dim myString As String

    For i = 2 To 11
    myString = Range("A" & i)
    Range("B" & i) = Left(myString, Len(myString) - 2)
    Next i
    
End Sub

Column B displays each of the strings in column A with the first two characters removed.

Note: You can find the complete documentation for the VBA Right method .

The following tutorials explain how to perform other common tasks using VBA:

x