(Solved) – Selecting cells with similar value and then renaming the texts chronologically

  • by
(solved)-–-selecting-cells-with-similar-value-and-then-renaming-the-texts-chronologically

enter image description here

I would like to automatically rename cells with the same value. For example, in a range I have selected, there are 3 cells with “stackoverflow”. The desired output would be to select those cells then change the text to something like this

stackoverflow_1
stackoverflow_2
stackoverflor_3

I’ve done the renaming part, but what I’m having trouble with is how you could select similar cells in a range. Here is what I have so far. Hopefully I could create a for loop or do while loop for this.

Sub rename()
num = WorksheetFunction.CountA(Selection)

Do While num <> 0

With Selection
    .Cells(num, 1).Value = Selection.Cells(num, 1) & "_" & num
End With
num = num - 1
Loop
End Sub

Leave a Reply

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