how can I sum a variable number of columns within one row

msampson

Board Regular
Joined
Mar 9, 2004
Messages
124
Office Version
  1. 365
Platform
  1. MacOS
I have a large data set with each different row being a different entity and many columns of calculations and inputs for that entity. I need to sum a variable number of columns of data depending on the age in column A for that particular entity.
In other words I have each possible age in columns AG:CQ and I want to sum from AG to whatever column matches the actual age in A. I assume some version of index, match and possibly sumif is what I need to combine.

A. AG. AH. AI. AJ. AK. AL. AM. AN. AO. AP. AQ. AR. AS
1. age. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32
2 25
3. 31

So for the patient in row 2 I would want to sum from AG2:AL2 but for the patient in row 3 I would want to sum AG3:AR3

Maureen
Excel for Mac v 16.42
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

How about
Excel Formula:
=SUM(AG2:INDEX(AG2:CQ2,A2-19))
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,508
Office Version
  1. 365
Platform
  1. Windows
Another option that would require no maintenance if the values in AG1:CQ1 were changed (eg starting at 18 instead of 20)

20 12 29.xlsm
ABCAGAHAIAJAKALAMANAOAPAQARAS
120212223242526272829303132
225337465928958544
331561715319487371
SUM variable
Cell Formulas
RangeFormula
B2:B3B2=SUMIF(AG$1:CQ$1,"<="&A2,AG2:CQ2)
 
Last edited:
Solution

msampson

Board Regular
Joined
Mar 9, 2004
Messages
124
Office Version
  1. 365
Platform
  1. MacOS
Thanks! I got the first one to work, but I like the simplicity of the second one.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,674
Messages
5,637,726
Members
416,981
Latest member
PLonchar

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
Top