VBA Code to append incremental number to duplicate values to make it unique

Narendra Babu D

New Member
Joined
Nov 22, 2024
Messages
1
Office Version
  1. 365
Platform
  1. MacOS
I have a column with some duplicate values in it. I do not want to eliminate it but append the duplicate text with incremental numbers starting form 1 to make them unique.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
If you want the suffix number from the second appearance, use bold part.
Or from the first appearance, use the red line
Rich (BB code):
Sub test()
    With Intersect(Columns("a"), ActiveSheet.UsedRange).Offset(1)  '<--- change "a" to actual column.
        .Replace "_*", "", 2
        .Value = .Parent.Evaluate(Replace("if(#<>"""",#&if(countif(offset(#,,,row(1:" & .Rows.Count & _
        ")),#)>1,""_""&countif(offset(#,,,row(1:" & .Rows.Count & ")),#)-1,""""),"""")", "#", .Address))
        '.Value = .Parent.Evaluate(Replace("if(#<>"""",#&""_""&countif(offset(#,,,row(1:" & _
            .Rows.Count & ")),#),"""")", "#", .Address))
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top