Setting column reference in sumproduct

jamie_in_nj

Board Regular
Joined
Oct 29, 2009
Messages
58
I am using the sumproduct function in a worksheet to show some present values; i.e.,

<TABLE style="WIDTH: 130pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=174 border=0><COLGROUP><COL style="WIDTH: 77pt; mso-width-source: userset; mso-width-alt: 3766" width=103><COL style="WIDTH: 53pt; mso-width-source: userset; mso-width-alt: 2596" width=71><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD class=xl75 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; WIDTH: 77pt; BORDER-BOTTOM: #d4d0c8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" width=103 height=17>Amt_Yrs</TD><TD style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; WIDTH: 53pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" width=71>PV (EGP)</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl75 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>1</TD><TD class=xl74 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" align=right>1,194,386</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl75 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>2</TD><TD class=xl74 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" align=right>2,475,460</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl75 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>3</TD><TD class=xl74 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" align=right>3,827,974</TD></TR></TBODY></TABLE>
etc.

where the formula in B2 is
=SUMPRODUCT(GAAP!$C$111:$C$111,GAAP!$C$112:$C$112)

and the formula in B3 is
=SUMPRODUCT(GAAP!$C$111:$D$111,GAAP!$C$112:$D$112)

and the formula in B4 is
=SUMPRODUCT(GAAP!$C$111:$E$111,GAAP!$C$112:$E$112)

etc.

Is there a way to set the end column (i.e., C, D, E, etc.) to be dependent on the values in column A (i.e., 1, 2, and 3)? For the first three I just set the C, D and E manually, but that's pretty time-consuming.

Thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Let's say that the range ends at Column Z, try...

B2, copied down:

=SUMPRODUCT(GAAP!$C$111:INDEX(GAAP!$C$111:$Z$111,ROWS(B$2:B2)),GAAP!$C$112:INDEX(GAAP!$C$112:$Z$112,ROWS(B$2:B2)))

Change the range accordingly.
 
Upvote 0
Very cool. That works. I changed the Z to AY, since that is the last column of my values.

So ROWS(B$2:B2) returns 1, ROWS(B$2:B3) returns 2, etc, and

INDEX(GAAP!$C$111:$Z$111,1) returns GAAP!$C$111:$C$111
and
INDEX(GAAP!$C$111:$Z$111,2) returns GAAP!$C$111:$D$111
etc?
 
Upvote 0
So ROWS(B$2:B2) returns 1, ROWS(B$2:B3) returns 2, etc,

Yes...

INDEX(GAAP!$C$111:$Z$111,1) returns GAAP!$C$111:$C$111
and
INDEX(GAAP!$C$111:$Z$111,2) returns GAAP!$C$111:$D$111
etc?

Actually, INDEX(GAAP!$C$111:$Z$111,1) returns GAAP!$C$111. However, GAAP!$C$111:INDEX(GAAP!$C$111:$Z$111,1) returns GAAP!$C$111:$C$111, and GAAP!$C$111:INDEX(GAAP!$C$111:$Z$111,2) returns GAAP!$C$111:$D$111, and so on.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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