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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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