Anyway to use OFFSET & MATCH together?

JadeWitte

New Member
Joined
Jun 27, 2012
Messages
6
I have two spreadsheets in the same workbook. Both spreadsheets a have a similar layout for the monthly columns portion. 12 columns with the "month" name for column headers and below each monthly header a numerical #. For the first 12 months 1 -12 entered under each month respectively. Following the 12th month, there is is a column with the header "Total" and the year, then comes another 12 columns with the monthly headers and 13 -24 entered under each month, then another column with "Total" and the year, and so forth for 5 years. Note: for each "Total" column there is no sequential monthly identifier number like the months have. This is the reason this formula is challenging...for me at least.

In the spreadsheet ('Bus Dev'!) where the formula is input, the formula looks above in its column to see the numerical value associated with the month (cell T13 in the formula below). For instance, if we are in the 2nd year under the April column, the numerical value is 16 (12 months for the 1st year plus 4 (April) for the 2nd year. Once I have this numerical value (16) I add it to another variable that uses a VLOOKUP function to determine if I need to add 2, 1, 0, -1, -2 months to this value. If the VLOOKUP function returned a -2, then the monthly numerical value is 14 (16 -2 ). I then can use this to look up the data on the other spreadsheet ('S-OEM'!) (that has a similar structure) using INDEX (MATCH) functions returning the column over from the left in which the data resides. This gets around the issue with the "totals" column since, if I'm in a cell next to or within 2 columns of the totals column, my calculation is impacted if I were to just OFFSET by the VLOOKUP value. By using INDEX (MATCH) it finds the correct column every time. But of course there has always got to be a wrench thrown in to make things more difficult... ;)

Once I get to the correct column on the spreadsheet with the data, I'm using the SUMPRODUCT function to compare 4 columns of the same row (all the way down the spreadsheet) and if all 4 conditions are met (which only one row per column meets all 4 criteria) the formula gives me a value 57 rows below the trigger row (where all 4 criteria are met) and in the same column. I then use this SUMPRODUCT value to do other calculations back on the spreadsheet with the formula ('Bus Dev'!). Here is the formula that I'm using that finds the correct value on the data sheet (and it works):

=INDEX('S-OEM'!$H$17:'S-OEM'!$AY$1519,SUMPRODUCT(--('S-OEM'!$G$17:$G$1519="Headcount:")*--(OFFSET('S-OEM'!P$17:P$1519,0,(VLOOKUP('Bus Dev'!$C20,'Bus Dev'!$J$7:$N$10,5)-2))="")*--(OFFSET('S-OEM'!P$17:P$1519,0,(VLOOKUP('Bus Dev'!$C20,'Bus Dev'!$J$7:$N$10,5)-1))="")*--(OFFSET('S-OEM'!P$17:P$1519,0,(VLOOKUP('Bus Dev'!$C20,'Bus Dev'!$J$7:$N$10,5)))>1)*'S-OEM'!$A$17:$A$1519)+57,MATCH('Bus Dev'!T13+VLOOKUP('Bus Dev'!$C20,'Bus Dev'!$J$7:$N$10,5),'S-OEM'!$H$17:$AY$17,0))

The OFFSETs are checking to make sure there is no headcount 2 months prior and 1 month prior to headcount being > 1 in the column where my answer is found. So the problem comes in when I'm within 2 columns of the "totals" column (i.e. months Nov & Dec, and Jan & Feb), because when the OFFSET shifts over 2 columns there is no monthly numerical value under the "Total" column heading.

Below is the part of the formula that does the look up and finds the correct column on the data spreadsheet ('S-OEM'!):

MATCH('Bus Dev'!T13+VLOOKUP('Bus Dev'!C20,'Bus Dev'!$J$7:$N$10,5),'S-OEM'!$H$17:$AY$17,0)

Is there a way, to embed the MATCH function above into the three SUMPRODUCT arguments/arrays?
(I don't necessarily need to embed it in the "Headcount" argument since it is static and will be used in every formula as I copy it across).

Here is the first of the three arguments:

--(OFFSET('S-OEM'!P$17:P$1519,0,(VLOOKUP('Bus Dev'!$C20,'Bus Dev'!$J$7:$N$10,5)-2))="")

If I try replacing the: 'S-OEM'!P$17:P$1519 portion of formula with:

MATCH('Bus Dev'!T13+VLOOKUP('Bus Dev'!C20,'Bus Dev'!$J$7:$N$10,5),'S-OEM'!$H$17:$AY$17,0) I get an error message.

Any suggestions? Thank you very much!!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Well, after pulling an all-nighter I figured this out and wanted to share in case anyone is running into the same issue. Due to the "Totals" columns being inserted between each 12 calendar months, the OFFSET function is not the way to go. The... MATCH('Bus Dev'!T13+VLOOKUP('Bus Dev'!C20,'Bus Dev'!$J$7:$N$10,5),'S-OEM'!$H$17:$AY$17,0) portion of the formula needed to be leveraged differently and not in conjunction with OFFSET as I was trying to do. Below is the correct formula. What is awesome about this formula is that I can copy it down and across and throughout the spreadsheet and it pulls the correct numbers. Exciting for a guy that has been using massive nested IF statements for a long time and only last week learned (from this site!!) the power of SUMPRODUCT, MATCH and INDEX. Now my spreadsheets will be dynamic!! Pretty cool to have a paradigm shift like this! I'm glad I discovered this site! Thanks again. Here is the formula:

=IF(OR(O$13+VLOOKUP('Bus Dev'!$C25,'Bus Dev'!$J$7:$N$10,5)<3,O$13+VLOOKUP('Bus Dev'!$C25,'Bus Dev'!$J$7:$N$10,5)>65),"",INDEX('S-OEM'!$H$17:$AY$1519,SUMPRODUCT(--('S-OEM'!$G$17:$G$1519="Headcount:")*--(INDEX('S-OEM'!$H$17:$AZ$1519,0,MATCH('Bus Dev'!O$13-2+VLOOKUP('Bus Dev'!$C25,'Bus Dev'!$J$7:$N$10,5),'S-OEM'!$H$17:$AY$17,0))="")*--(INDEX('S-OEM'!$H$17:$AZ$1519,0,MATCH('Bus Dev'!O$13-1+VLOOKUP('Bus Dev'!$C25,'Bus Dev'!$J$7:$N$10,5),'S-OEM'!$H$17:$AY$17,0))="")*--(INDEX('S-OEM'!$H$17:$AZ$1519,0,MATCH('Bus Dev'!O$13+VLOOKUP('Bus Dev'!$C25,'Bus Dev'!$J$7:$N$10,5),'S-OEM'!$H$17:$AY$17,0))>1)*'S-OEM'!$A$17:$A$1519)+57,MATCH('Bus Dev'!O$13+VLOOKUP('Bus Dev'!$C25,'Bus Dev'!$J$7:$N$10,5),'S-OEM'!$H$17:$AY$17,0)))
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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