Quote Originally Posted by framcc06 View Post
how would I modify it on the test2 file where I want to compare Column B in both sheets, then import the values from Column A in sheet 1 into Column D of sheet2.
VLookUp is designed to look up a vaue in the leftmost column of a range and return the value in one of the columns to the right of it. In this case it's easier to use Index/Match (Vlookup can be used to lookup to the left but it's convoluted to do so and I've never made it work in vba, only on a sheet). This code is designed to work on your Test2.xlsm file:
Sub GetValues5()
Set rng1 = Range(Worksheets("Sheet1").Range("B2"), Worksheets("Sheet1").Range("B" & Rows.Count).End(xlUp))
Set rng2a = Range(Worksheets("Sheet2").Range("B2"), Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp))
Set rng2b = rng2a.Offset(, -1)
'---------------------------
'either:
cc = Application.Index(rng2b, Application.Match(rng1, rng2a, 0))

'or (if you've got more than 1 column to process you can use the same index):
'dd = Application.Match(rng1, rng2a, 0)
'cc = Application.Index(rng2b, dd)
'---------------------------
For i = 1 To UBound(cc)
  If IsError(cc(i, 1)) Then cc(i, 1) = Empty
Next i
rng1.Offset(, 2).Value = cc
End Sub