kiriloff
kiriloff

Reputation: 26333

Excel VBA script modify text trimming first 4 characters

I would like to write VBA script to trim the first characters in each row.

I know i can format cells with Cells Format > custom

But if i want to compare the content of the cells later, the trimmed characters are nevertheless taken into account in the comparison.

I am new to VBA, how can i quickly trim text for text comparison ?

Upvotes: 0

Views: 965

Answers (1)

Gary's Student
Gary's Student

Reputation: 96771

Select the cells you want to trim and run this tiny macro:

Sub trimmit()
    For Each r In Selection
        v = r.Text
        r.Value = Mid(v, 5)
    Next r
End Sub

I am assuming that if a cell contains ABCDE, it will become E

Upvotes: 3

Related Questions