You can use the following formula to combine the IF function with INDEX and MATCH in Excel:
=IF(B1="Mavs",(INDEX(A7:D9,MATCH("Guard",A7:A9,0),3)),IF(B1="Pacers",(INDEX(A13:D15,MATCH("Guard",A13:A15,0),3))))
This particular formula first checks if the value in cell B1 is equal to “Mavs” – if it is then it looks for “Guard” in the range A7:A9 and returns the value in column 3 of the range A7:D9.
However, if the value in cell B1 is “Pacers” then it looks for “Guard” in the range A13:A15 and returns the value in column 3 of the range A13:D15.
The following example shows how to use this formula in practice.
Example: Use IF Function with INDEX MATCH in Excel
Suppose we have two datasets that display various information about basketball players on two different teams:
Now suppose we would like to return the rebounds value for the Guard on either the Mavs or the Pacers team, depending on the team name that we type into cell B1.
To do so, we can type the following formula into cell B2:
=IF(B1="Mavs",(INDEX(A7:D9,MATCH("Guard",A7:A9,0),3)),IF(B1="Pacers",(INDEX(A13:D15,MATCH("Guard",A13:A15,0),3))))
The following screenshot shows how to use this formula in practice:
Since the value in cell B1 is set to “Mavs” the formula returns the rebounds value for the Guard from the Mavs dataset, which turns out to be 2.
If we change the value in cell B1 to “Pacers” then the formula will automatically update to return the rebounds value for the Guard from the Pacers dataset instead:
The formula now returns a value of 4, which represents the rebounds value for the Guard from the Pacers dataset.
Additional Resources
The following tutorials explain how to perform other common tasks in Excel:
Excel: How to Use SUM with INDEX MATCH
Excel: Use INDEX MATCH to Return Multiple Values Vertically
VBA: How to Use INDEX MATCH