Vlookup through VBA

macro_user

Board Regular
Joined
Mar 9, 2009
Messages
101
hi...
i need to use vlookup through my code in VBA...

VLOOKUP(A4,'sheet1'!F:G,2,FALSE)

A4 is the data which im doing the Vlookup... its present in sheet1 at F and i need the column value G... so the column index is 2 and i keep match exact case as FALSE...

so wat i need to know is, i need to iterate through each value in column A and get the value at B...

can i write something like this...?

for i = 1 to lastrow_in_col_A
cells(i+3,"B").value = Vlookup('A' & i + 3 ,'sheet1'!F:G,2,FALSE)
next i

is it possible for me to loop through every value in column A? tat is wat i need to know...
appreciate ur help...
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You should be able to do that without a loop:

Code:
Sub test()
Dim lastrow_in_Col_A As Long
lastrow_in_Col_A = Range("A" & Rows.Count).End(xlUp).Row + 3
With Range("B4:B" & lastrow_in_Col_A)
    .Formula = "=VLOOKUP(A4,'sheet1'!F:G,2,FALSE)"
    .Value = .Value
End With
End Sub

If you actually want the formula in the cell instead of the result:

Code:
Sub test()
Dim lastrow_in_Col_A As Long
lastrow_in_Col_A = Range("A" & Rows.Count).End(xlUp).Row + 3
Range("B4:B" & lastrow_in_Col_A).Formula = "=VLOOKUP(A4,'sheet1'!F:G,2,FALSE)"
End Sub
 
Upvote 0
gr8... let me try this... I'm amazed at the speed of the replies at this forum... its really good... you guys are doing a great job...
Keep it going...
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,513
Members
448,967
Latest member
screechyboy79

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