Re: VLOOKUP through code?
Check out Application.WorksheetFunction in the help files....
Re: VLOOKUP through code?
Pozzi ...
Is the Week Date/Week # table pre-loaded for the entire duration, or does it get updated periodically. The reason I ask is because VLOOKUP references an array of cells, and it is a little tricky if the array keeps changing size.
With this consideration, YES, you can easily use VLOOKUP to do what you want to do.
You need to consider if you will be looking for an exact date, or if you are allowing a date between the lookup table entries. There is a parameter in the VLOOKUP function that controls this.
The easiest way to set up the code is to record a macro and do an Insert > Function and fill in the blanks in the wizard.
Let us know if this solves your problem.
Re: VLOOKUP through code?
Quote:
Originally Posted by Webtest
The reason I ask is because VLOOKUP references an array of cells, and it is a little tricky if the array keeps changing size.
If the array size is changing you can always use a "Dynamic Named Range" that will always reflect the full array size.
Range names in Excel are really formulas that refer to a range and you can write these in such a way that the dynamically expand as your dataset increases.
In the Inset\Name\Define dialogbox
Basic Range Name Formula: =Calendar!$A$1:$B$2
Dynamic Range Name Formula: =OFFSET('Calendar'!$A$1,0,0,COUNTA('Calendar'!$A:$A),COUNTA('Calendar'!$1:$1))
The dynamic range name creates a range using the offset function, offsetting from A1 to the cell that is CountA(A:A) down and CountA(1:1) across. (Remember that the range reference is just a formula and you can include any excel function in it).
As you add rows to your dataset, the value of CountA(A:A) increases, so your range grows downward.
As you add additional Column headers, the value of CountA(1:1) increases, so your range grows horizontially.
I use these all the time for Lookup Tables and they can make life much easier...
Note: this approach really only woks if you have a single lookup range per worksheet.