Lookup a Column Range by Matching Heading

jcoeng

New Member
Joined
May 11, 2011
Messages
15
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hello!

I've got an accounting spreadsheet that is used to total up various items. One item is provided in a pivot table that I can't modify but changes over time.

I have a working solution but references are hard-coded. I need help making the lookups dynamic based on column headers. More details in the linked file and mini sheet below.

Mini-sheet below
Fruit totals.xlsx
BCDEFGHIJKLMNOP
2This table's content grows longer as new fruits are addedThis table also grows as fruits are added and as time goes on
3New colors may be added, can be in alphabetical orderNew fruits will be in alphabetical order so hard coded column references break
4I don’t have the color in the main pivot table
5
6Fruits grouped by colorPivot table of pounds of fruit sold each month
7Green FruitOrange FruitRed FruitYearMonthApplesCateloupeCherriesKiwiMangoWatermelon
8KiwiMangoCherries2023110753420
9WatermelonCanteloupeApples2023215537822
10202337895718
112023415944614
12
13Table to fill needs the same formula in each cell
14Correlate date shown with year and month in pivot table
15Find the column color group by matching header
16Look only at fruits in the color groups,
17Sum all values in each color group for each month
18Existing formula works but breaks easily when pivot table updates with new data
19The tables below are representative, in use they have other data in rows between the monthly totals so I cant use a separate pivot table
20Table below uses hard coded references
21
22Green FruitOrange FruitRed Fruit
232023-01-3123
242023-02-28
252023-03-31
262023-04-30
27
28desired result
29Green FruitOrange FruitRed Fruit
302023-01-31231115
312023-02-28291318
322023-03-31231516
332023-04-30181519
Sheet1
Cell Formulas
RangeFormula
C23C23=INDEX(N8:N11,MATCH(1,(I8:I11=YEAR(B23))*(J8:J11=MONTH(B23)),0))+INDEX(P8:P11,MATCH(1,(I8:I11=YEAR(B23))*(J8:J11=MONTH(B23)),0))


I've cross-posted a similar question in the google sheets forum but no replies over there yet. The primary work is in GSheets so if there are tricks to use that make it easier than excel, please let me know.

Thank you!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Is this going to be in Excel or Google Sheets?
If excel what is your version of excel? (Please update your profile so your version appears in your button.)

An excel solution may not work with google sheets.
 
Upvote 0
Here is a pivot table that updates when you put the data in Tables and use power query.
I made this in the linked workbook. You can open it there.

Fruit totals.xlsx
ABCDEFGH
35
36
37
38Sum of SalesColumn Labels
39Row LabelsGreen FruitOrange FruitRed FruitGrand Total
402023
41123111549
42229131860
43323151654
44418151952
45Grand Total935468215
46
47
Sheet1
 
Upvote 0
I added the info to my profile, thank you for letting me know it was there. Ultimately the solution will be needed in google sheets,

The data gathered from the pivot table will be mixed into another sheet on a per-row basis with other transactions so ultimately I think I'll need a formulaic solution but maybe I can create a helper table...hmmm

I was able to get a partial solution using match and address to find the starting cell of each range, I just couldn't turn that into a usable range for the index function.
 
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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