Macros - Vlookups & Ranges

geoffcraver

New Member
Joined
Aug 14, 2008
Messages
8
Hello,

I'm working on a macro that performs vlookups. The issue I have is that both the lookup value and table array needed for the vlookup will be variable lengths every time.

So if I have a 'Summary' tab where my lookup value starts in A2, how do I stop the vlookup when it hits a blank cell in column A?

Also how do I create a dynamic range for the table array on the 'data' tab?


Thank You
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Welcome to the board...

Here's some common code to find the last non empty cell in a column
LastRow = Cells(Rows.Count,"A").End(xlup).Row

Then you can use that in a range like
Range("A1:A" & LastRow)

Hope that helps.
 
Upvote 0
I appreciate the help Jonmo. This might be a dumb follow up.
How do I make a dynamic range absolute? Normally you can just say $A$2:$B$20, but how do I absolute the range when its ("A1:B"&LastRow)?


Thanks
 
Upvote 0
A manual process...you can try making a named range.
Select the sheet with your range then from the menu (Insert, Name, Define)

Name your range (Say Dynamic_Range1) and for the refers to use the below code:
Code:
 =OFFSET(URPAGE!$A$1,0,0,COUNTA(URPAGE!$A:$A),COUNTA(URPAGE!$1:$1))
Replace URPAGE with the name of your sheet...

Note:
This will make your range dynamic for rows AND columns.
When you replace URPAGE with your sheetname, do outside of the refers to area as while you type it sometimes automatically changes your formula to something you cannot use.
Sheet names may not be able to have spaces. (from my experience in xl 2000)

Now you can refer to Dynamic_Range1 and when you do it will pickup rows and columns dynamically.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,904
Members
449,477
Latest member
panjongshing

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