Forum Discussion
ZJacobsmeyer1990
Jul 25, 2025Copper Contributor
Data with Mix of Unique and Duplicate IDs - Create new column that creates Unique IDs for all
I have a data set where I have a mix of unique and duplicate transaction IDs. I am trying to figure out a way to create a MACRO that can complete the following on different data extracts with the sam...
HansVogelaar
Jul 25, 2025MVP
Let's say your IDs are in D2 and down.
A formula solution:
Enter the following formula in E2 or another cell in row 2:
=D2&"-"&COUNTIF(D$2:D2,D2)
Fill down.
A macro solution:
Sub CreateUniqueIDs()
Const col = 4 ' column D
Dim m As Long
Application.ScreenUpdating = False
Cells(1, col + 1).EntireColumn.Insert
m = Cells(Rows.Count, col).End(xlUp).Row
With Range(Cells(2, col + 1), Cells(m, col + 1))
.FormulaR1C1 = "=RC[-1]&""-""&COUNTIF(R2C[-1]:RC[-1],RC[-1])"
.NumberFormat = "@"
.Value = .Value
End With
Application.ScreenUpdating = True
End Sub
ZJacobsmeyer1990
Jul 25, 2025Copper Contributor
This worked perfectly. Thank you!!