We all love LOOKUP functions in Excel and the heart favourite is VLOOKUP. We are well introduced to VLOOKUP and have already seen VLOOKUP in action several times, but we never came across a situation where we have multiple ranges to look up and have to switch between them based on a condition.
For example, to calculate wages of workmen you have defined different rates depending on hours worked. Up to this point situation is easy as we can used VLOOKUP formula to easily fetch the rate corresponding to correct number of hours within data range. But what if you have different rates if labour force exceeds standard working hours?
In this case you will have two ranges; one range for hours worked upto standard hours and second for hours worked above standard hours. So how can we make a lookup function to jump between two ranges and give us the right hourly rate?
The solution is easier than you think. As now we have a condition that “if hours worked are above standard hours then use second range otherwise use first range to fetch the hourly rate”. This is exactly our approach in Excel too and we will accomplish it using Excel’s very famous IF function.
Named ranges – Making things easier
Names manager let you name specific range of cells and that makes many things simple and easy to write, refer and understand. So lets have this done before we assemble our functions together.
Step 1: Open up the file you downloaded and you will find two ranges named upto standard hours and the second one as above standard hours . Select cell B14 and drag the selection to cell C21 and hit Ctrl+F3 which will invoke names manager.
Step 2: Click new button and in the dialogue box that appears type range1 in the name field.
Step 3: Repeat same steps for second range but name it range2.
Following animation shows naming for range1:
VLOOKUP + IF = Multiple range LOOKUP is born!
Go to cell C4 and type the following formula:
I always say that if you have formula containing multiple functions always start with the most inner function and that will make sense much easier as Excel follows the same approach too. So in this case we have IF function sitting in the middle.
Reminding you what I said in the beginning:
“If hours worked are above standard hours then use second range otherwise use first range to fetch the hourly rate”
In excel it is put in function like this:
Cell B1 contains the standard hours information. Excel first compares the hours in cell B4 (that are actual hours worked) with hours in cell B1 (standard hours). This will help establish if the range1 (range that contains rate if actual hours worked are upto standard hours allowed) is to be used or range2 (range that contains rate if actual hours worked exceeds standard hours) is to be used.
In simple words if hours in cell B4 are more than the hours mentioned in cell B1 then use range2 otherwise use range1 to fetch rates.
Once range is decided, VLOOKUP kicks in and it will start looking up in column B. Remember while naming ranges we selected two columns B and C with several rows where column B contains hours information and column C contains corresponding rates.
For Iron man who worked 50 hours it exceeded standard hours therefore Excel will jump to range2 i.e. B25:C32.
And thus the formula will practically shorten to this:
It will start looking for hours and will find a closest match on row 30 in column B and as formula has mentioned “2″ that means value to be fetched is in second column in the selected range therefore it will go to cell C30 and fetch a rate of 30.
Now double click the fill handle so that rest of the cells can populate with the same formula and you have rates calculated for you in no time by doing lookups in two ranges following the condition.
So this is how you do look ups on multiple ranges using conditions. Don’t forget to checkout Excel tutorials collection. And yes there is one more surprise for you if you are not already aware of it. We have started LIVE Excel Sessions or webinars where we are inviting known Excel heads to share their knowledge and expertise with us. And yes we have done one session already and next is tomorrow at 10:00PM Pakistan time. Head over to this page to learn more about upcoming sessions and webinars.
And lastly, don’t forget to signup for our free Excel newsletter to receive Excel updates, articles and everything else related to Excel right in your inbox.