VBA code to create vlookup formula in range

RoccoM

New Member
Joined
Apr 22, 2019
Messages
19
Guys:
I have to create a vlookup for a range of cells. I have included an example below.
Here is my problem. How do I account for the formula when I do not know how many rows there will be in my range?
I already created a variable to store my row count, not sure on the rest.
Example: here is my current lookup formula that I created manually. ( obviously I know the range): =VLOOKUP(AE2,$AC$2:$AD$64828,2,FALSE

I copied my data into the same sheet so I can count the rows and store it into a variable. I just need help with using variable in my lookup formula; or is there an easier way?


Example data:
RCD:TYPERCD:FUNCTIONCreate FromLookup: Function Field
3C16942ASWITCHBLANK-PNL-19INCH-2CABINET_SUPPLY
3C17111ETH_SWITCHMODULEBLANK-PNL-19INCH-2CABINET_SUPPLY
3C17121ETH_SWITCHMODULEBLANK-PNL-19INCH-2CABINET_SUPPLY
3C17131ETH_SWITCHMODULEBLANK-PNL-19INCH-2CABINET_SUPPLY
3C17203SWITCHBLANK-PNL-19INCH-1CABINET_SUPPLY
3C17203SWITCHBLANK-PNL-19INCH-1CABINET_SUPPLY

<tbody>
</tbody>


Thank you,
Rocco
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
How about
Code:
Sub RoccoM()
   Dim UsdRws As Long
   UsdRws = Range("AE" & Rows.Count).End(xlUp).Row
   Range("AG2:AG" & UsdRws).Formula = "=vlookup(AE2,$AC$2:$AD$" & UsdRws & ",2,0)"
End Sub
 
Last edited:
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,423
Messages
6,119,398
Members
448,892
Latest member
amjad24

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