Hi
Sid on this site kindly posted the following code to sort excel data based on the content of rows from another tab in excel. I would like to do is for it to then sort the output into unique rows so that I can show only the unique records of one of the output columns. the code is as follows.
Sub Sample()
Dim ws1 As Worksheet
Dim ws1LastRow As Long
Set ws1 = Sheets("Sheet1")
With ws1
ws1LastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Columns("B:B").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
.Range("B2").FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet2!C[-1],1,0)"
.Range("B2").AutoFill Destination:=Range("B2:B" & ws1LastRow)
.Range("B2:B8").Copy
.Range("B2:B8").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
.Range("B1").FormulaR1C1 = "Temp"
.Range("A1:C8").Select
Application.CutCopyMode = False
.Columns("A:C").Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
.Range("A1:C1").AutoFilter
.Range("$A$1:$C$" & ws1LastRow).AutoFilter Field:=2, Criteria1:="#N/A"
.Range("$A$1:$C$" & ws1LastRow).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
.Columns("B:B").Delete Shift:=xlToLeft
.Range("A1:C1").AutoFilter
End With
End Sub
Open in new window
Sort-Example.xls