Question

I have a spreadsheet that is calculating sale rep commissions for 12 months.

On my Spreadsheet, I have a cell (H32) that when I enter a 1, then it calculates their Year To Date Attainment and/or Year To Date Quota, based on that number of months. That way the YTD is correct, up through that month. So, cell C4 would be for July (or period 1 of that fiscal year). At the end (cell P4) totals the Sum of each cell (C4, D4, E4, etc), through all 12 months and that formula is: =SUM(C4:N4) I currently have to manually add in the month at the end of each period.

For example:

If I need to calculate July, August and September, when August closes out the formula is =SUM(C4:D4), but in order to get September in there at the end of that month, in order to show the YTD total, I have to physically change that formula to =SUM(C4:E4).

What I would like to do is create a Conditional If/Then statement or formula that will automatically calculate in the next cell in the chain (D4, E4, F4, etc), based on the number that I place in the aforementioned cell H32.

For Example:

If there is a 4 in H32, then the cell P4 would automatically update to: =SUM(C4:F4). If I change cell H32 to a 7, then the cell P4 would automatically update to: =SUM(C4:I4)

Was it helpful?

Solution

This is a prime candidate for the INDIRECT function.

From http://office.microsoft.com/en-us/excel-help/indirect-HP005209139.aspx

Use INDIRECT when you want to change the reference to a cell within a formula without changing the formula itself.

Your example would be something like

=SUM(C4:INDIRECT("R4C"&$H$32+2, FALSE))

Note that I'm using the R1C1 notation. If H32 is 7, then the INDIRECT formula will evaluate to R4C7, a.k.a., G4. Then we add 2 to the column to make it I7.

Hope that makes sense, please comment if you want further clarification.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top