inserting vlookup via VBA help

abhaysanan

Board Regular
Joined
Jun 1, 2005
Messages
95
I'm trying to do a vlookup with vba where my lookup value changes per row.

Code:
For j = row To i
    If ActiveSheet.Cells(j, 5) = "USD" And Sheets("TempExtract").Cells(1, 8) = "USD" Then
        ActiveSheet.Cells(j, col).Formula = "=VLOOKUP(Cells(j,6),TempExtract!A:M,7,FALSE)"
        ActiveSheet.Cells(j, col).Copy
        ActiveSheet.Cells(j, col).PasteSpecial xlPasteValues
    End If
Next j

The value I want to lookup is in column 6 of every row. I need to look up that value from another sheet and Insert it into another column in the same row. I cant seem to make my look up value correspond to te current row though. This is pretty simple I guess but I just cant figure out the syntax. Thanks!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
1) Use a variable name other than "row," as it that is a VBA property. You could use "myrow," for example. Just (try to) make sure it's not something used in VBA.

2) You want to reference the cell in the formula, so do not include it within the quotes holding the formula. In the sample code you posted above, "Cells(j,6)" is considered part of the formula and not a cell reference. You have to separate it from the formula text:
Code:
"=VLOOKUP(" & Cells(j,6) & ",TempExtract!A:M,7,FALSE)"
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top