Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default sum number of columns based on variable value

I need to add the values in columns C2 to AL2 with the number of columns to
be included in the SUM depending on a variable that is entered by the user.
Cells C2 to AL2 contain the values and the row below C3 to AL3 contain the
formula to add the specified number of columns in the row above.

For example, if the user enters the value 3 in cell A1 then the formula
should add the 3 columns preceeding the cell with the formula. If the formula
is in cell G3, then the cells E2:G2 should be added. If the forumla is in
cell H3 then the cells F2:G2 should be added and so on.

I need something like this, if this formula were in cell G3: Sum(G2-A1:G2).
I know this is not the correct syntax but hopefully it shows what I am trying
to do.

Thank you in advance for your help.


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 347
Default sum number of columns based on variable value

Hi,
Try this in C3:

=SUM(INDIRECT(CHAR(MAX(65,65+COLUMN()-$A$1))&2&":"&CHAR(64+COLUMN())&2))

copy across to AL3

HTH
Jean-Guy

"rt10516" wrote:

I need to add the values in columns C2 to AL2 with the number of columns to
be included in the SUM depending on a variable that is entered by the user.
Cells C2 to AL2 contain the values and the row below C3 to AL3 contain the
formula to add the specified number of columns in the row above.

For example, if the user enters the value 3 in cell A1 then the formula
should add the 3 columns preceeding the cell with the formula. If the formula
is in cell G3, then the cells E2:G2 should be added. If the forumla is in
cell H3 then the cells F2:G2 should be added and so on.

I need something like this, if this formula were in cell G3: Sum(G2-A1:G2).
I know this is not the correct syntax but hopefully it shows what I am trying
to do.

Thank you in advance for your help.


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default sum number of columns based on variable value

That worked perfectly. Thank You!!

"pinmaster" wrote:

Hi,
Try this in C3:

=SUM(INDIRECT(CHAR(MAX(65,65+COLUMN()-$A$1))&2&":"&CHAR(64+COLUMN())&2))

copy across to AL3

HTH
Jean-Guy

"rt10516" wrote:

I need to add the values in columns C2 to AL2 with the number of columns to
be included in the SUM depending on a variable that is entered by the user.
Cells C2 to AL2 contain the values and the row below C3 to AL3 contain the
formula to add the specified number of columns in the row above.

For example, if the user enters the value 3 in cell A1 then the formula
should add the 3 columns preceeding the cell with the formula. If the formula
is in cell G3, then the cells E2:G2 should be added. If the forumla is in
cell H3 then the cells F2:G2 should be added and so on.

I need something like this, if this formula were in cell G3: Sum(G2-A1:G2).
I know this is not the correct syntax but hopefully it shows what I am trying
to do.

Thank you in advance for your help.


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default sum number of columns based on variable value

This formula works up to column Z, however, once I get into the columns AA,
AB, etc I get a #REF! error. I think the CHAR function is returning a symbol
rather than a letter from Char(91) and on.

How can I get the formula to work for columns beyond Z?

Thanks


"pinmaster" wrote:

Hi,
Try this in C3:

=SUM(INDIRECT(CHAR(MAX(65,65+COLUMN()-$A$1))&2&":"&CHAR(64+COLUMN())&2))

copy across to AL3

HTH
Jean-Guy

"rt10516" wrote:

I need to add the values in columns C2 to AL2 with the number of columns to
be included in the SUM depending on a variable that is entered by the user.
Cells C2 to AL2 contain the values and the row below C3 to AL3 contain the
formula to add the specified number of columns in the row above.

For example, if the user enters the value 3 in cell A1 then the formula
should add the 3 columns preceeding the cell with the formula. If the formula
is in cell G3, then the cells E2:G2 should be added. If the forumla is in
cell H3 then the cells F2:G2 should be added and so on.

I need something like this, if this formula were in cell G3: Sum(G2-A1:G2).
I know this is not the correct syntax but hopefully it shows what I am trying
to do.

Thank you in advance for your help.


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 347
Default sum number of columns based on variable value

Hi,

Sorry for being late, I did not see your last post until now!

This should work better:

=SUM(INDIRECT(ADDRESS(2,MAX(1,COLUMN()-$A$1))&":"&ADDRESS(2,COLUMN())))

Cheers!
Jean-Guy

"rt10516" wrote:

This formula works up to column Z, however, once I get into the columns AA,
AB, etc I get a #REF! error. I think the CHAR function is returning a symbol
rather than a letter from Char(91) and on.

How can I get the formula to work for columns beyond Z?

Thanks


"pinmaster" wrote:

Hi,
Try this in C3:

=SUM(INDIRECT(CHAR(MAX(65,65+COLUMN()-$A$1))&2&":"&CHAR(64+COLUMN())&2))

copy across to AL3

HTH
Jean-Guy

"rt10516" wrote:

I need to add the values in columns C2 to AL2 with the number of columns to
be included in the SUM depending on a variable that is entered by the user.
Cells C2 to AL2 contain the values and the row below C3 to AL3 contain the
formula to add the specified number of columns in the row above.

For example, if the user enters the value 3 in cell A1 then the formula
should add the 3 columns preceeding the cell with the formula. If the formula
is in cell G3, then the cells E2:G2 should be added. If the forumla is in
cell H3 then the cells F2:G2 should be added and so on.

I need something like this, if this formula were in cell G3: Sum(G2-A1:G2).
I know this is not the correct syntax but hopefully it shows what I am trying
to do.

Thank you in advance for your help.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating values in two columns based on a variable Alex Excel Discussion (Misc queries) 3 January 23rd 07 07:18 PM
Macro - Using a variable number of columns in a Range stumped Excel Discussion (Misc queries) 2 October 3rd 06 08:13 PM
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 PM
adding variable number of columns confused Excel Worksheet Functions 5 September 23rd 05 10:09 AM
Chart based on variable number of columns Scott Hamilton Charts and Charting in Excel 2 June 5th 05 03:36 PM


All times are GMT +1. The time now is 11:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"