Home » excel » vba – Excel Match, Index VLOOKUP Multiple Criteria

vba – Excel Match, Index VLOOKUP Multiple Criteria

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to populate a cell, and only display value if it does not already exist. If it exists, then display another value.

…But I cannot get my head around how to do this.

I currently have the following formula placed on cells in the E column

=INDEX(config!H2:H20,
MATCH(1,
(F4=config!F2:F20)*(VLOOKUP(D4,config!C2:D20,2,FALSE)=config!G2:G20),0))

This matches some other criteria as you can see here. However, what you can also see is the value 7 is getting displayed twice. I’m wanting it not to display any values in use.

enter image description here
So, I then added an extra column, called ‘Room In Use’ in a config sheet, where the data is coming from… this column has some formulas to check if the values are in use

=NOT(ISERROR(MATCH(H2,Sheet1!E2:E41,0)))

You can see this in action here: enter image description here

So, going back to my sheet1, I think this formula needs another condition to say If room in use == FALSE then do

=INDEX(config!H2:H20,
MATCH(1,
(F4=config!F2:F20)*(VLOOKUP(D4,config!C2:D20,2,FALSE)=config!G2:G20),0))

else if all rooms are TRUE then display ‘None Available’

I tried using:

{=INDEX(config!H2:H20,MATCH(1,(F5=config!F2:F20)*("FALSE"=config!J2:J20)*(VLOOKUP(D5,config!C2:D20,2,FALSE)=config!G2:G20),0)) }

but to no avail…

Is this even possible in an excel formula or will I need to use VBA?

I have attached my excel document here: https://www.dropbox.com/s/crmbbp8esdvnv29/Book1.xlsm?dl=0

How to&Answers:

To achieve the first, second, third, etc matches, you need to switch to a SMALL(IF(… or AGGREGATE to return the matching row numbers to INDEX where the k argument is provided by a progressive COUNTIF or COUNTIFS of already used values on the local worksheet.

While an overly complicated single formula may be ultimately possible, your use of the double lookup matching column D to config!C:C to return a value in config!D:D could use a ‘helper’ column to ease the conditional count.

Put this formula into M2 (optionally use a custom number format of ;;;) then drag down through M2:M20.

=VLOOKUP(D2, config!C:D, 2, FALSE)&F2

The formula in E2:E20 is now,

=INDEX(config!H:H,
       AGGREGATE(15, 7, ROW($2:$20)/((config!F$2:F$20=F2)*(config!G$2:G$20=VLOOKUP(D2, config!C:D, 2, FALSE))), 
       COUNTIF(M$2:M2, VLOOKUP(D2, config!C:D, 2, FALSE)&F2)))

Don’t be surprised to receive an error in E16. This will be rectified once you fix the typo in D16. All other #NUM! errors occur when you run out of possible matching values.