My Excel worksheet contains a lot of VLOOKUPs on a named range that I have defined. Now, when I added a column in the middle of my named range, the VLOOKUPs that reference columns after the inserted column are now broken. I understand the problem, but what is the best way to fix? Is there a way to figure out the column number from the header text?
[EDIT]
Using Kaze's idea of INDEX and MATCH seemed to be the best solution. Here's what I ended up with:
INDEX(MyTableData, MATCH("RowLabel", RowList, 0), MATCH("ColumnLabel", ColumnList,0))
where MyTableData is a named range of the entire table, RowList is a named range of the row header, and ColumnList is a named range of the column headers.
Best Answer
Personally, I prefer using an
INDEX-MATCH
combo for lookups instead ofVLOOKUP
. Here's an example off the Pokedex I was compiling for my niece.To get Squirtle's Hidden Ability, I'd use this formula:
This yields the same result as:
One good thing about INDEX-MATCH is that in most cases, you don't need to reference the entire data range, so the first formula should work even if you regularly add columns and rows to your data range. It also has another advantage: since you're referencing only 2 one-dimensional ranges, it calculates faster.
Nevertheless, you can still use
MATCH
with yourVLOOKUP
formulas to get the column number.where:
$A$1:$H$1
is the first row in your data/named range, or the row that contains header textNAMED_RANGE
is the name for your data range"COLUMN_TEXT"
is the header text for the column that contains the data you needC1
contains your lookup valueEdit: Added Index-Match example as per Doug's request. :D