close

This problem is doubly frustrating because I had it nailed down yesterday,
then my PC crashed and I lost my formula. And now I can't reproduce it....

I am trying to sum a number of items in a given row on another worksheet
(sheet 2), depending on whether the value in the header row in the
corresponding column falls between two values (call them A and B) in the
header row of my source worksheet (sheet 1). Let me demonstrate by example:

Sheet 1 Sheet 2
60 65 70 75 61 63 64 67 71 72
1 X 1 2 4 5 3 2
6
2 Y 2 1 0 4 2 1
3
3 Z 3 2 4 6 5 2
3

For X, the two values (A and B) between which sheet 2 header must fall
batween are 60 and 65. So I would expect X to be 2 4 5 = 11
For Y, A and B are 65 and 70, and I need to look at row 2, so Y = 2
Similarly Z should be 2 3 = 5

Now for an extra twist, I am selected different sheets using a combo box,
and linking that to a cell which is referred to by my formula so that I can
switch sheet 2 and it will update automatically.

Here's what I have, and I think its close to what I had before, but I'm
getting a #VALUE error message. It is array entered. The INDEX( ) function
refers to my list of sheets and my combo box selection.

=SUMPRODUCT(--((INDIRECT((INDEX($A$9:$A$72,$A$6))amp;quot;!B1:CW1quot;))gt;D$ 1),--((INDIRECT((INDEX($A$9:$A$72,$A$6))amp;quot;!B1:CW1quot;))lt;E$ 1),INDIRECT((ADDRESS(ROW(),COLUMN(B2),,,INDEX($A$9 :$A$72,$A$6)))amp;quot;:quot;amp;(ADDRESS(ROW(),COLUMN(CW2)))))

It looks messy, and I'm sure it could be tidied up, but (i think) I need to
use ADDRESS( ) because I have to be able to drag the cells down and across
and update the rows/columns accordingly, and using INDIRECT with cell refs as
strings does not update them when dragged.

Please can someone put me out of my misery, or suggest an altogether much
better way of achieving the same result.

Thanks in advance.

I have narrowed down the problem to the third array in the SUMPRODUCT
function. If I use
INDIRECT(INDEX($A$9:$A$72,$A$6)amp;quot;!B2:CW2quot;)
instead of
INDIRECT((ADDRESS(ROW(),COLUMN(B2),,,INDEX($A$9:$A $72,$A$6)))amp;quot;:quot;amp;(ADDRESS(ROW(),COLUMN(CW2))))
I get what I want. But I need to be able to drag the thing down and across
with relative references, otherwise I'll be changing 80,000 formulae manually.

This is driving me bonkers.quot;rmellisonquot; wrote:

gt; This problem is doubly frustrating because I had it nailed down yesterday,
gt; then my PC crashed and I lost my formula. And now I can't reproduce it....
gt;
gt; I am trying to sum a number of items in a given row on another worksheet
gt; (sheet 2), depending on whether the value in the header row in the
gt; corresponding column falls between two values (call them A and B) in the
gt; header row of my source worksheet (sheet 1). Let me demonstrate by example:
gt;
gt; Sheet 1 Sheet 2
gt; 60 65 70 75 61 63 64 67 71 72
gt; 1 X 1 2 4 5 3 2
gt; 6
gt; 2 Y 2 1 0 4 2 1
gt; 3
gt; 3 Z 3 2 4 6 5 2
gt; 3
gt;
gt; For X, the two values (A and B) between which sheet 2 header must fall
gt; batween are 60 and 65. So I would expect X to be 2 4 5 = 11
gt; For Y, A and B are 65 and 70, and I need to look at row 2, so Y = 2
gt; Similarly Z should be 2 3 = 5
gt;
gt; Now for an extra twist, I am selected different sheets using a combo box,
gt; and linking that to a cell which is referred to by my formula so that I can
gt; switch sheet 2 and it will update automatically.
gt;
gt; Here's what I have, and I think its close to what I had before, but I'm
gt; getting a #VALUE error message. It is array entered. The INDEX( ) function
gt; refers to my list of sheets and my combo box selection.
gt;
gt; =SUMPRODUCT(--((INDIRECT((INDEX($A$9:$A$72,$A$6))amp;quot;!B1:CW1quot;))gt;D$ 1),--((INDIRECT((INDEX($A$9:$A$72,$A$6))amp;quot;!B1:CW1quot;))lt;E$ 1),INDIRECT((ADDRESS(ROW(),COLUMN(B2),,,INDEX($A$9 :$A$72,$A$6)))amp;quot;:quot;amp;(ADDRESS(ROW(),COLUMN(CW2)))))
gt;
gt; It looks messy, and I'm sure it could be tidied up, but (i think) I need to
gt; use ADDRESS( ) because I have to be able to drag the cells down and across
gt; and update the rows/columns accordingly, and using INDIRECT with cell refs as
gt; strings does not update them when dragged.
gt;
gt; Please can someone put me out of my misery, or suggest an altogether much
gt; better way of achieving the same result.
gt;
gt; Thanks in advance.
gt;
gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()