Hi...i have this code below....what is does is take columns BA:BB into a Sheet1 into a temp sheet and sort it so that Sheet1 column AX can be populated with a formula that looks for column A in Column BA and returns BB...but the lookup happens in the temp sheet..so column BA and BB are columns A and B in the temp sheet.
I need to change it so that the AV is the column that has the lookup formula and AB is the column that has the value being looked up...i've tried to amend it but habe had no luck.
Dim wsData As Worksheet, wsTemp As Worksheet
Dim rng As Range
Set wsData = ActiveSheet
With wsData
Set rng = .Range("BA1:BB" & .Cells(.Rows.Count, "BA").End(xlUp).Row)
End With
Set wsTemp = Worksheets.Add
wsTemp.Range("A1").Resize(rng.Rows.Count, 2).Value2 = rng.Value2
Set rng = wsTemp.Range("A1").Resize(rng.Rows.Count, 2)
rng.Sort key1:=rng.Columns(1), order1:=xlAscending
With wsData
With .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
.Offset(, .Columns("AX:AX").Column - 1).FormulaR1C1 = _
"=IF(LOOKUP(RC1,'" & rng.Parent.Name & "'!" & rng.Columns(1).Address(1, 1, xlR1C1) & ")=RC1" & _
",LOOKUP(RC1,'" & rng.Parent.Name & "'!" & rng.Columns(1).Address(1, 1, xlR1C1) & ",'" & _
rng.Parent.Name & "'!" & rng.Columns(2).Address(1, 1, xlR1C1) & "),NA())"
.Offset(, .Columns("AX:AX").Column - 1).Value2 = .Offset(, .Columns("AX:AX").Column - 1).Value2
End With
End With
Bookmarks