VBA Vlookup variable range

BioExcel

New Member
Joined
Jun 27, 2014
Messages
13
still learning VBA and frequently bumping up to some errors. I currently have the following issue:

I have an excel with 2 worksheets (FORM and DATA).
sheet DATA contains 2 colums of data: A = lookup value. B = value to be returned. Range (A:B) is named data.
sheet FORM column B contains the lookup value (identical to DATA colum A). The number of rows for this column is variable, starting from B2.
Column C is empty and should receive a vlookup-formula via macro if the corresponding cel in column B is not empty.

I currently have the following:

Dim lR as long
lR= Range("B" & rows.count).end(x1up).row
range("C2").Formula= "=VLOOKUP(B2;data;2;FALSE)"
range("C2:C" & Range("B" & Rows.Count).end(x1up).row).filldown

when running the macro, I receive the error: application-defined or object-defined error.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
It should be xLup not x1up. Also in VBA you need to use , not ;

Try

Code:
Dim lR As Long
lR = Range("B" & Rows.Count).End(xlUp).Row
Range("C2").Formula = "=VLOOKUP(B2,data,2,FALSE)"
Range("C2:C" & lR).FillDown
 
Upvote 0
It should be xLup not x1up. Also in VBA you need to use , not ;

Try

Code:
Dim lR As Long
lR = Range("B" & Rows.Count).End(xlUp).Row
Range("C2").Formula = "=VLOOKUP(B2,data,2,FALSE)"
Range("C2:C" & lR).FillDown

Thx. have adjusted the code and works. (I'll keep in mind to use , instead of ; in vba. good hint :) )
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,709
Members
449,093
Latest member
Mnur

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