VBA to evaluate a cell value, and based on that value return a sum of a specific set of cells

Seanm290

New Member
Joined
Jan 24, 2013
Messages
9
I need a regular formula, or a macro that will evaluate a cell value (in my case, 1-12 representing fiscal periods), and based on that value, return a sum of specific cells. Is this best achieved using a macro or another formula type? Obviously, there will be 12 possible summations based on the cell value.

Thanks!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Possible formulae depend on how varied the different sums are. If there is a regular pattern you could try using the INDIRECT function to calculate the addresses to sum, or the OFFSET function. Another possibility is the CHOOSE function where you would list the twelve possible ranges. Hope that helps, but if you post more detail I could be more specific!

Keith
 
Upvote 0
Below is an example of what I'm looking for. In this case, period is 4, so the result should be 590.00. I believe there is a limit on how many formulae can be nested, so I don't think that will work (will it?).
Period4
Periods123456789101112
100.00 150.00 160.00 180.00 190.00 150.00 60.00 400.00 85.00 135.00 22.00 86.00
IF(B3=1,(B7))
IF(B3=2,(B7+C7))
IF(B3=3,(B7+C7+D7))
IF(B3=4,(B7+C7+D7+E7))
……
IF(B3=12,(B7+C7+D7+E7+F7+G7+H7+I7+J7+K7+L7+M7))

<tbody>
</tbody><colgroup><col span="13"></colgroup>
 
Upvote 0
I'm not sure how or why, but that worked! I've never heard of that function before.

Many thanks!
 
Upvote 0

Forum statistics

Threads
1,211,963
Messages
6,105,108
Members
447,947
Latest member
OX_2005

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