![]() |
|
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: May 2002
Posts: 5
|
I tried posting this once but it didn't seem to work, my apologies if it appears twice.
I would like to dynamically construct a range to be used in a SUM function but I can not get the addresses into the function after constructing them. For example, I create the addresses of lower and upper limits of the range using the ADDRESS function, and then I want to put them in the SUM function. I thought the following would work to add up only the data under the months up to this month (I have the data for 12 months in row 5 starting at column H): SUM(ADDRESS(ROW(F5),8,4):ADDRESS(ROW(F5),(7+MONTH(TODAY())),4)) but the output from the ADDRESS function is text and not accepted as an actual address. Can anyone help? Thank you, Brian |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, CO
Posts: 1,744
|
you could use indirect
=SUM(INDIRECT(ADDRESS(ROW(F5),8,4)&":"&ADDRESS(ROW(F5),(7+MONTH(TODAY())),4))) Or depending on your criteria, maybe a sumif statement maybe better suited. I'm not going to pretend I tried to figure out what you wanted to add here. |
|
|
|
|
|
#3 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: The Hague
Posts: 42,651
|
Quote:
If you build a range reference using the ADDRESS worksheet function, you need to deference it with INDIRECT before feeding the built range to another worksheet function. So: =SUM(INDIRECT(ADDRESS(ROW(F5),8,4)&":"&ADDRESS(ROW(F5),(7+MONTH(TODAY())),4))) should work. I might as well add that although fully legal, it's not most efficient way. Regards, Aladin |
|
|
|
|
|
|
#4 |
|
Join Date: May 2002
Posts: 48
|
The INDIRECT function returns the reference specified by text. Try something like:
SUM(IDIRECT(ADDRESS(ROW(F5),8,4)&":"&ADDRESS(ROW(F5),(7+MONTH(TODAY())),4))) |
|
|
|
|
|
#5 |
|
Join Date: May 2002
Posts: 5
|
Thank you both for you replies. It worked! I had tried using INDIRECT but did not include the &":"&. That was the problem.
Just out of curiosity Aladin, what is a more elegant way to achieve the same thing? Brian |
|
|
|
|
|
#6 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: The Hague
Posts: 42,651
|
Quote:
I'd use the OFFSET worksheet function to specify the range over which to compute SUM, etc. But, try to figure out whether the SUMIF function would serve your purpose as IML noted. Aladin |
|
|
|
|
|
|
#7 |
|
Join Date: May 2002
Posts: 5
|
SUMIF worked and was much simpler.
Thanks again, Brian |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|