ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Sum by variable column (https://www.excelbanter.com/excel-discussion-misc-queries/111293-sum-variable-column.html)

gr

Sum by variable column
 
I am having trouble wrapping my brain around this one.

I have a listing of columns for months (in reverse order). In each row
is that months budget numbers. What I want to do is have a column that
sums the year to date based on a value that is typed into a cell.
Colunn U = Jan
column T = Feb
Column S = March
etc

So if I type a 1, I want the sum of row x columns U:U
If I type a 3, I want the sum of row x columns S:U
etc

Thanks in advance for any help.
Guy


Bob Umlas

Sum by variable column
 
If that number is in cell A1, for example, this formula will do what you
want (fill down):
=SUM(OFFSET(J2,0,12-A1,1,A1))

"gr" wrote in message
oups.com...
I am having trouble wrapping my brain around this one.

I have a listing of columns for months (in reverse order). In each row
is that months budget numbers. What I want to do is have a column that
sums the year to date based on a value that is typed into a cell.
Colunn U = Jan
column T = Feb
Column S = March
etc

So if I type a 1, I want the sum of row x columns U:U
If I type a 3, I want the sum of row x columns S:U
etc

Thanks in advance for any help.
Guy




Rand451

I put the months in row 2, columns J to U. With U2 = Jan

Cell A2 is reserved for the number of columns. Recommend you use data validation or some kind of drop-down list to restrict the user to 12 max.

x values go in B3 to whatever

The following formula was filled down from A3 to whatever

=SUM(OFFSET($U$2,$B3,1,1,1):OFFSET($U$2,$B3,-$A$2+1,1,$A$2))

$U$2 = Jan
$B3 = x = this row, column 2
$A$2 = # months

in R1C1 notation: =SUM(OFFSET(R2C21,RC2,1,1,1):OFFSET(R2C21,RC2,-R2C1+1,1,R2C1))

hth...

Quote:

Originally Posted by gr
I am having trouble wrapping my brain around this one.

I have a listing of columns for months (in reverse order). In each row
is that months budget numbers. What I want to do is have a column that
sums the year to date based on a value that is typed into a cell.
Colunn U = Jan
column T = Feb
Column S = March
etc

So if I type a 1, I want the sum of row x columns U:U
If I type a 3, I want the sum of row x columns S:U
etc

Thanks in advance for any help.
Guy


Rand451

Guy's solution is better than mine...

I made a minor change to it: =SUM(OFFSET($U$2,$B3,-$A2+1,1,$A$2))

$U$2 = Jan
$B3 = x value
$A2 = # of months



All times are GMT +1. The time now is 02:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com