Adding a unique name to duplicate values in a column

dominikapabis

New Member
Joined
Feb 9, 2016
Messages
4
Hello,

I need help writing a VBA macro that will search for duplicates in a column and add a unique identifier. So that I can mark some, not all for deletion further on in my macro ( I already have that part written out)

For Example:

[TABLE="width: 300"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]AAA
[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]BBB[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]AAA[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]BBB[/TD]
[/TR]
</tbody>[/TABLE]




[TABLE="width: 300"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]AAA
[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]BBB[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]AAA #1[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]BBB #2[/TD]
[/TR]
</tbody>[/TABLE]



Here's the catch...

After the rest of my code runs, I need to remove the remaining unique identifiers in the column also in a macro.

I would greatly appreciate any help!

Thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I probably don't understand your question right, but why don't you just insert a column at column 'A', fill it in with incrementing numbers (1, 2, 3 etc.), do stuff, and then delete Column A to delete the unique identifiers?
 
Upvote 0
I'm not sure about the second part of your question, but try this (in a copy of your workbook) for appending the identifiers to the duplicate values.

Rich (BB code):
Sub AppendNums()
  Dim a As Variant
  Dim d As Object
  Dim i As Long, k As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
  For i = 1 To UBound(a)
    If Len(a(i, 1)) Then
      If d.exists(a(i, 1)) Then
        k = k + 1
        a(i, 1) = a(i, 1) & " #" & k
      Else
        d(a(i, 1)) = 1
      End If
    End If
  Next i
  Range("A1").Resize(UBound(a)).Value = a
End Sub
 
Upvote 0
I'm not sure about the second part of your question, ..
On re-reading, perhaps it is just this

Rich (BB code):
Sub RemoveIdentifiers()
  Range("A1", Range("A" & Rows.Count).End(xlUp)).Replace What:=" #*", Replacement:="", LookAt:=xlPart, SearchFormat:=False, ReplaceFormat:=False
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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