Should I use an Index or Vlookup?

gbtwo

New Member
Joined
Apr 9, 2012
Messages
38
I'm going to use the following Table below as an example. What kind of Index formula could I use that could look through the table and find instances of "Dog" and color "Red" and bring back the other values in the row?
DuckDaffyBlue2XMichigan
MouseMickeyRed3XOhio
MouseMinnieGreen3XMichigan
DogGoofyRed2XOhio
DogPorkyGreen1XGeorgia
BunnyBugsRed4XFlorida
DogPlutoRed3XTexas
[td]Animal[/td]
[td]Name[/td]
[td]Color[/td]
[td]Size[/td]
[td]State[/td]
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:
This is an array formula and must be entered with CTRL-SHIFT-ENTER.
Copy formula down and across as needed. Change ranges to match your data.
Excel Workbook
ABCDEF
1AnimalNameColorSizeState
2DuckDaffyBlue2XMichigan
3MouseMickeyRed3XOhio
4MouseMinnieGreen3XMichigan
5DogGoofyRed2XOhio
6DogPorkyGreen1XGeorgia
7BunnyBugsRed4XFlorida
8DogPlutoRed3XTexas
9
10AnimalDog
11ColorRed
12
13NameSizeState
14Goofy2XOhio
15Pluto3XTexas
16
Sheet
 
Upvote 0
As a Florida resident, I have to point out that Florida is a yellow dog state. 'scuse me, a yaller dog state. :rolleyes:

I might approach this in a couple of ways. If I'm always searching for the same keys, and especially if the table is large (hundreds or thousands of rows), I would create a hidden column which concatenates all the key columns. Then I'd use Match to search that column for the combined key value, and use the returned value to Index the row of the table. (You could also use Vlookup in this case, by placing the hidden column to the left of the table. However, that requires using Vlookup once for each value you want to retrieve. Match is better for retrieving multiple values.)

If the search is complex -- for example if the user is allowed to specify any combination of one to four columns to use as search keys -- then I would go into VBA and write a loop to go through the table. This will probably perform fine for hundreds of rows. If the table gets into thousands of rows and the search is getting executed constantly (IOW not just when the user punches a button), then performance might be slow. In that case you would need to reconsider how to store and search the data.

Edward

PS: I don't doubt AhoyNC's proposal, but making changes to it -- for example, using a different number of key columns, or even adding rows to the table -- will require understanding what has to be changed. It does avoid VBA and hidden columns.
 
Upvote 0

Forum statistics

Threads
1,216,124
Messages
6,128,995
Members
449,480
Latest member
yesitisasport

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