Hope someone can see the flaw here.
Attached file Duplicated Uniques.xlsm has letter combinations in Col A. Each "unique" combination needs to have a "Group number" assigned to it.
The Macro below creates the list of "Unique" combinations in Col I, sorts them and creates sequential Group Numbers in Col J.
But for some reason it allows two versions of one combination that you will see in Cells I18 and I19, and I can't see why?
Option Explicit
Sub Uniques()
Dim a As Long, j As Long, x As Long
Application.ScreenUpdating = False
'Find number of rows to copy
a = Range("A65536").End(xlUp).Row
'Filter Unique values
Range("I2").Select
Range("A2:A" & a).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
"I2"), Unique:=True
Range("J2").Select
j = Range("I65536").End(xlUp).Row
'Assign Group Names to each unique value
ActiveCell.FormulaR1C1 = "1"
Range("J2:J" & j).Select
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
'Index/Match to Groups
Range("B2").Select
ActiveCell.FormulaR1C1 = "=INDEX(C[8],MATCH(RC[-1],C[7],0))"
Range("B2").Select
Selection.Copy
Range("B2:B" & a).Select
ActiveSheet.Paste
Application.CutCopyMode = False
'Convert to values
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A2").Select
' Sort by Col D
Range("I2:I" & j).Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("I2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("I2:I" & j)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("I1").Select
'
Application.ScreenUpdating = True
End Sub
All suggestions received gratefully
Ochimus
Bookmarks