Hi Jenny
I have looked at your data and I think that there is an easy solution to this.
Insert three new columns to the left of your data.
Copy all your data into column A
Use the remove duplicate function to remove duplicates
in column 3 insert a formula to look for an exact match of the numbers in column A for the numbers in column 4
If an exact match exists then display the number in column A.
Copy Paste your values
Repeat for all your columns
Delete the last column.
Simples Really.
Ok Try this Macro:
Sub Macro2()
'
' Macro2 Macro
'
'
Columns("A:C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
LCR = Selection.SpecialCells(xlCellTypeLastCell).Row
Pos = 1
For Count = 4 To LCR
LR = Cells(Rows.Count, Count).End(xlUp).Row
If Cells(LR, Count) <> "" Then
Range(Cells(1, Count), Cells(LR, Count)).Copy Destination:=Range("A" & Pos)
Pos = Pos + LR
End If
Next
ActiveSheet.Columns("A:A").RemoveDuplicates Columns:=1, Header:=xlNo
LR = Cells(Rows.Count, 1).End(xlUp).Row
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:A" & LR)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
For Count = 3 To LCR - 1
Range(Cells(1, Count), Cells(LR, Count)).FormulaR1C1 = "=IF(ISNA(MATCH(RC1,R1C[1]:R21C[1],0)),"""",RC1)"
Range(Cells(1, Count), Cells(LR, Count)).Value = Range(Cells(1, Count), Cells(LR, Count)).Value
Next
End Sub
Bookmarks