How do I remove the first two characters from all cells in a selection using VBA?

836 Views Asked by At

In order to make my macro work, I've added a double # onto the start of each cell using VBA -> ##string

However, I now need to remove the double hashtag for all cells in the selection, I'm using the below code to target all cells in my worksheet.

Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select

I would like to know if there is a way to first, highlight all of the data like I have above, then use something like a 'LEFT TRIM' formula to trim the first two characters of each cell in the selection.

Or if anyone has any other solutions, I would be open to them too.

1

There are 1 best solutions below

0
On

This will remove (up to) the first two characters from cells within the selected area:

For Each cell In Application.Selection
    cell.Value = Right(cell.Value, Application.Max(0, Len(cell.Value) - 2))
Next cell