Try this code:
Sub Macro1()
'Steps:
' - add sequential numbers in column D to save original sort order
' - add formula: This enters "YES" if Variant Title is the first one in the set, or
' enters "NO" if not the first one in the set, or
' leaves blank if cell in column A is blank
' - sort all (A-D) by columns A & C ascending
' - copy formulas in column B as values
' - sort back to the original sort order
' - clear cells in temporary sorting column D
'
'Result: the first-occurring lowest column C dollar value for each set of values in column A displays "YES"
'in column B, or "YES" for the 1st occurence in the set of values in column A if all $ values are equal.
'All other column B cells for data rows display "NO", and column B remains blank where column A cell is blank.
'
Dim rowCount As Long, i As Long
Dim strFormula As String
rowCount = Cells(Rows.Count, "C").End(xlUp).Row
Application.ScreenUpdating = False
Cells(1, 4).Value = "SortCol"
Range("B2:B" & rowCount).Select
Selection.NumberFormat = "General"
For i = 2 To rowCount
Cells(i, 4).Value = i
strFormula = "=IF(TRIM(A" & i & ")=" & Chr(34) & Chr(34) & _
"," & Chr(34) & Chr(34) & "," & _
"IF(A" & i & "<>A" & (i - 1 & "," & """YES""" & "," & """NO""))")
Cells(i, 2).Formula = strFormula
Next
Range("A1:D" & rowCount).Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
Range("B2:B" & rowCount).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1:D" & rowCount).Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns("D:D").ClearContents 'clear column used to restore sort order
Range("A1").Select
Application.ScreenUpdating = True
End Sub
Bookmarks