COUNTING & SUMMING MULTIPLE SHEETS!

  • Thread starter Thread starter gr8guy
  • Start date Start date
G

gr8guy

HI,

suppose i hv 3 sheets viz., Sheet1, Sheet2, Sheet3 & i hv data on :

Sheet1 as :
========
COL A B C
ROW 1 PRADEEP REALERROR 0:30
NOS 2 RHYS REALERROR 0:25
3 PRADEEP REALERROR 0:35
4 RHYS DAVOXERROR 0:25
5 PRADEEP REALERROR 0:22
6 PRADEEP DAVOXERROR 0:32
7 PRADEEP DAVOXERROR 0:45


Sheet2 as :
========
COL A B C
ROW 1 RHYS REALERROR 0:34
NOS 2 RHYS REALERROR 0:22
3 PRADEEP REALERROR 0:35
4 RHYS DAVOXERROR 0:20
5 PRADEEP REALERROR 0:22
6 PRADEEP DAVOXERROR 0:32
7 PRADEEP REALERROR 0:49


now on Sheet3, i want to calculate the TOTAL no of times the error occured
for each person & the total summation of time for each error.
I knw that it requires using the functions like INDIRECT, MATCH, SUMPRODUCT,
COUNTIF, SUMIF, but i dont knw how to go about doing it as each column would
require a different function. PLEASE NOTE that actually there are 31 sheets
& this is just an example of 2 sheets to make it easier.


Sheet3 would look like, starting at Column A onwards:

NAME ERROR NO OF ERRORS TOTAL TIME
====================================================
PRADEEP REALERROR e.g 6 times (need formula) e.g
3:13 mins (need formula)
DAVOXERROR e.g 6 times (need formula)
(need formula)

RHYS REALERROR (need formula) (need
formula)
DAVOXERROR (need formula) (need
formula)

Can anybody help me???

Rgds,

Eijaz
 
The general approach to conditional counting and summing across worksheets is to
start with a list of the worksheet names. If such a list can be generated by
formula as an array, do that. For example, Sheet2, Sheet3 and Sheet4 are given
by "Sheet"&ROW(INDIRECT("2:4")). However, Bob, Carole, Ted and Alice would
require either a constant array, {"Bob","Carole","Ted","Alice"} or a reference
to a range containing them in separate cells.

Use this list, for which I'll use the token WSLST, to generate an array of text
references, e.g., ="'"&WSLIST&"'!B:B". Wrap this inside INDIRECT. The result
from INDIRECT will be something that resembles an array of range references.
(This is undocumented territory, so there's no official terminology.) Wrap this
inside COUNTIF or SUMIF (which seem to be the only two functions that handle
such objects robustly), and wrap that inside SUMPRODUCT.

So to count pa particular type of error across multiple worksheets,

=SUMPRODUCT(COUNTIF(INDIRECT("'"&WSLST&"'!B:B"),"REALERROR"))

and to sum times for each type of error across multiple worksheets,

=SUMPRODUCT(SUMIF(INDIRECT("'"&WSLST&"'!B:B"),"REALERROR",
INDIRECT("'"&WSLST&"'!C:C")))
 
Hi Harlan,

I tried your code in the night & it works for only worksheets without any
blank rows & having uniform range columns. if one worksheet has more rows &
other has less, it gives an error #REF.
i knw Countif can only count non-blank cells. what if there are blank rows
in some of the worksheets.
See what i hv made is a Downtime error workbook having 31 worksheets for the
31 days & named each worrksheet as a number e.g sheet names r 1,2,3....31 &
in the final worksheet, i have to count & sum the MONTH2DATE DATA.

all worksheets r similar & having so have the same no of rows. i want to get
the count & sum in the final month2date worksheet as:
if suppose i hv entered 1...31 nos in a1.....a31 on the final worksheet &
named the range "sheets",
=sumproduct(countif(indirect("'"&sheets&"'!"d9:d69"),"pradeep")), where
d9:d69 is the range which i hv to count consisting of errors like:
real error
davox error
citrix error, etc....

the above formula takes into consideration only one condition i.e.
"pradeep".
1) what if i want to count with 2 conditions,
"pradeep" & "real error", what do i do?
2) secondly, if there are some blank rows in between some worksheets, is
there a formula which will not consider the blank rows & gv me the total
count.
3) do i hv to keep the column range uniform i.e. d9:d69? what if there are
more entries to be made on one of the sheets, can i use a variable range &
what would the formula if such is the case?

Please help & thanks for your fast reply!

Best regards,

Eijaz
 
I tried your code in the night & it works for only worksheets without any
blank rows & having uniform range columns. if one worksheet has more rows &
other has less, it gives an error #REF.

The formulas:

By using entire column references in the formulas I provided in my previous
response, the SUMIF and COUNTIF functions will operate over the entire columns
in each worksheet. No rows would be missed.

The only way these formulas could give #REF! errors is if there were entries in
WSLST that weren't names of worksheets in the file containing the cells in which
these were the formulas. What does your WSLST range look like? What do your
*EXACT* formulas look like?
i knw Countif can only count non-blank cells. what if there are blank rows
in some of the worksheets.

They should be skipped, no? You're trying to count the number of cells that
match particular criteria. Is one of the criteria being blank?
See what i hv made is a Downtime error workbook having 31 worksheets for the
31 days & named each worrksheet as a number e.g sheet names r 1,2,3....31 &
in the final worksheet, i have to count & sum the MONTH2DATE DATA.

F U wnt 2 txt, I cn 2, bt I doubt U cn Ndrstand. How 'bout using English?
all worksheets r similar & having so have the same no of rows. i want to get
the count & sum in the final month2date worksheet as:
if suppose i hv entered 1...31 nos in a1.....a31 on the final worksheet &
named the range "sheets",
=sumproduct(countif(indirect("'"&sheets&"'!"d9:d69"),"pradeep")), where
d9:d69 is the range which i hv to count consisting of errors like:
real error
davox error
citrix error, etc....

If you're not going to use entire column references, then you'd be far better
off using common worksheet-level names for the ranges you want to process in
each worksheet, then use those common names rather than range references in the
formula.
the above formula takes into consideration only one condition i.e.
"pradeep".

OK, I missed the multiple criteria. SUMIF and COUNTIF are the only built-in
functions that seem to handle INDIRECT(<array_of_textrefs>) [first] arguments,
so they're the only two functions that can do any sort of 3D conditional summing
and counting. As both allow for only one criteria, 3D conditional summing and
counting is limited to single criteria.

Your options are adding another column to each of the data worksheets in which
you concatenate your distinguishing fields (person and error type), then use
SUMIF and COUNTIF on this new column, or use add-in or user-defined functions to
do this. Given your data layout, you should consider downloading and installing
Laurent Longre's MOREFUNC.XLL add-in, available fro

http://liongre.free.fr/english/

It provides a function named THREED which you could use with 3D references like
'1:31'!D9:D69 to create 2D arrays (with the ranges from each worksheet stacked
vertically below the range from the preceding worksheet) that could be fed to
SUMPRODUCT.
2) secondly, if there are some blank rows in between some worksheets, is
there a formula which will not consider the blank rows & gv me the total
count.

Blank 'rows' between 'worksheets'? Do you mean blank rows in the worksheet list?
If so, you have to get rid of those blank rows. If you mean blank rows in the
given range in some of the worksheets in the list, they should be ignored. But
this becomes academic if you need multiple criteria and decide to use THREED.
3) do i hv to keep the column range uniform i.e. d9:d69? what if there are
more entries to be made on one of the sheets, can i use a variable range &
what would the formula if such is the case?

Again, this is academic if you need multiple criteria and decide to use THREED.
However, you could replace the WSLST from my original response with a list of
text references to ranges to check in each worksheet. So instead of WSLST like

1
2
:
31

you could use RNGLST like

'1'!D9:D69
'2'!D9:D103
:
'31'!D9:D45

Then use

=SUMPRODUCT(COUNTIF(INDIRECT(RNGLST),criteria))

to count matching records. To sum, you could use

=SUMPRODUCT(COUNTIF(INDIRECT(RNGLST),criteria,OFFSET(INDIRECT(RNGLST),0,n)))

since OFFSET can also handle INDIRECT(array_of_textrefs) as first argument.

*****!!!!!*****

Actually, this is something new to me. If I had worksheets A, B and C, with
A!A1:F6 containing the formula =1000000+1000*ROW()+COLUMN() , B!A1:F6
containing the formula =2000000+1000*ROW()+COLUMN() and C!A1:F6 containing the
formula =3000000+1000*ROW()+COLUMN() , then the formula

=N(OFFSET(INDIRECT({"A","B","C"}&"!A1"),{0;0;1;1;2;2;3;3},{0;1;0;1;0;1;0;1}))

returns the array

{1001001,2001001,3001001;
1001002,2001002,3001002;
1002001,2002001,3002001;
1002002,2002002,3002002;
1003001,2003001,3003001;
1003002,2003002,3003002;
1004001,2004001,3004001;
1004002,2004002,3004002}

which gives you close to the functionality of THREED without the syntactic
support for 3D references, *but* allowing arbitrary combinations and ordering of
worksheets.

Note: this only works for numbers. Replace N() with T() if the ranges contain
text. If the ranges contain a mixture of numbers and text, I suppose a huge IF
formula could sort them out, but I'm not going to try just yet.

This is new to me. I'm not going to suggest anything more until I've played with
it for a while.
 
Hi Harlan,
Sorry i sent you a wk file w/o your permission!

But i am frustrated that i am not able to come up with a formula which would
count & some on the final sheet using multiple criteria ( in my case 2
criteria).

Did you receive the file?

Rgds,

Eijaz
 
gr8guy said:
Sorry i sent you a wk file w/o your permission!

But i am frustrated that i am not able to come up with a formula which would
count & some on the final sheet using multiple criteria ( in my case 2
criteria).

Did you receive the file?

Yes, I received the file, and this is one of the few times I opened an
e-mail attachment. I used the OFFSET(INDIRECT(..WSLST..),..) technique I
mentioned in my last response, and it works. It produces LONG formulas, but
you can't have everything. I copied your Final worksheet and named the copy
HG, then I entered the formulas for multiple condition, multiple *worksheet*
sums and counts in HG. The cells with these formulas are formatted with
yellow backgrounds. I also entered WSLST in a range in HG, and formatted
those cells with green backgrounds.

I put the resulting workbook in a zip file and uploaded it to

ftp://members.aol.com/hrlngrv/scms.zip
 
Thanks a Bunch Harlan!

You really made my day! thats a cool idea about defining a name refering to
a range with a name(WBase) & also Seq & wrapoing in offset & giving it
Sumproduct!

Thanks once again! Will try this out & keep you posted! Right now really
tired after a long night's work!


Best Rgds,

Eijaz
 
Hi Harlan,

I tried using your formula to get a count & sum for 31 sheets on the final
sheet, but it is not giving me a count & only a value of zeroes, but no
errors.

now, is it bcos i hv given data validation on every cell in AGENTS column &
ERROR column to choose agents & the corresponding error they had for the
day, on all 31 sheets. & is it bcos i started entering data from the 20th
sheet onwards till date i.e. 26th, so it is not calculating & giving the
results (i.e. count of Errors & sum of Time lost) bcos of the starting blank
sheets( & ending one also)?

Also, since i hv a cell e.g "A5" on every sheet (its actually a merged cell
i.e. merged from A5 to C5) on top which gives me the most occuring error for
the day,

i use an Array formula for the error range C9:C69:

{=INDEX(C9:C69,MATCH(MAX(COUNTIF(C9:C69,C9:C69)),COUNTIF(C9:C69,C9:C69),0))}

to get the most occuring error for that day.

pls note, since 1st 19 sheets r empty, so the cell shows 0. after 20th the
cell shows the error. now i md a named range, using your idea i.e named,

WSE = "'"&WSLST&"'!B2"
& used that in the final sheet to calculate the final error which occured
over the month i.e. which occured max in the 31 sheets. BUT IT SHOWS 0. but
when i entered some data in the 01st sheet, (i.e. selected some agents &
some errors from the drop-down lists), i got the 1st error for the day
reflecting in the final sheet.
i used the array formula:

{=INDEX(INDIRECT(WSE),MATCH(MAX(COUNTIF(INDIRECT(WSE),INDIRECT(WSE))),COUNTI
F(INDIRECT(WSE),INDIRECT(WSE)),0))}

Is it bcos of blank cells & no data entered in the initial 19 sheets?

Lastly, i am not able to understand, why you hv taken the named range:

Seq = ROW(INDIRECT("1:20"), can i take it as ROW(INDIRECT("1:69") or
ROW(INDIRECT("9:69"), as my column range starts from the 9th row.

for WSBase = "'"&WSLST&"'!A1" , do i hv to refer to the initial cell A1?

I hv understood the named range WSLST refering the 31 sheets from 01....31.

If the blank cells or the blank sheets r the cause, then i would hv to
change the whole format & enter data again! PLS HELP!

Waiting in anticipation for your early reply!

Best Regards,


Eijaz
 
gr8guy said:
now, is it bcos i hv given data validation on every cell in AGENTS column &
....

Write in English. I haven't the time to decipher you @#$@#% txting.
 
Hi Harlan,

Sorry about my English! i apologise for the same!

I tried using your formula to get a count & sum for 31 sheets on the final
sheet, but it is not giving me a count and only a value of zeroes, but no
errors.

1) Now, is it because i have given data validation on every cell in AGENTS
column and ERROR column to choose agents and the corresponding error they
had for the day, on all 31 sheets. and is it because i started entering data
from the 20th sheet onwards till date i.e. 26th, so it is not calculating
and giving the results (that is, count of Errors and sum of Time lost)
because of the starting blank sheets(and ending ones also)?

2) Also, since i have a cell e.g "A5" on every sheet (its actually a merged
cell that is, merged from A5 to C5) on top which gives me the most occuring
error for the day,

i use an Array formula for the error range C9:C69:

{=INDEX(C9:C69,MATCH(MAX(COUNTIF(C9:C69,C9:C69)),COUNTIF(C9:C69,C9:C69),0))}

to get the most occuring error for that day.

Please note, since 1st 19 sheets are empty, so the cell shows 0. after 20th,
the cell shows the error. now i made a named range, using your idea that is,
named,

WSE = "'"&WSLST&"'!B2"

and used that in the final sheet to calculate the final error which occured
over the month that is, which occured maximum in the 31 sheets. BUT IT SHOWS
0. but when i entered some data in the 01st sheet, (that is, selected some
agents and some errors from the drop-down lists), i got the 1st error for
the day reflecting in the final sheet.

i used the array formula:

{=INDEX(INDIRECT(WSE),MATCH(MAX(COUNTIF(INDIRECT(WSE),INDIRECT(WSE))),COUNTI
F(INDIRECT(WSE),INDIRECT(WSE)),0))}

Is it because of blank cells and because no data is entered in the initial
19 sheets?

Lastly, i am not able to understand, why you have taken the named range:

Seq = ROW(INDIRECT("1:20"), can i take it as ROW(INDIRECT("1:69") or
ROW(INDIRECT("9:69"), as my column range starts from the 9th row.

for WSBase = "'"&WSLST&"'!A1" , do i have to refer to the initial cell A1?

I have understood the named range WSLST refering the 31 sheets from
01....31.

If the blank cells or the blank sheets are the cause, then i would have to
change the whole format & enter data again! PLS HELP!

Waiting in anticipation for your early reply!

Best Regards,


Eijaz
 
...
...
I tried using your formula to get a count & sum for 31 sheets on the final
sheet, but it is not giving me a count and only a value of zeroes, but no
errors.

If you don't get errors but only zeros, then the odds are that there are no
actual matches. That could be due to stray trailing ASCII space or nonbreaking
space characters in your cell entries. Pick a worksheet that appears to contain
a match, and enter some diagnostic COUNTIF formulas, e.g.,

=COUNTIF(X9:X69,"SomeTextHere")

where X is just a placeholder for one of your actual columns and "SomeTextHere"
is another placeholder for text which seems to appear in the given range. If you
get zero results, you likely have stray trailing spaces. If so, clean your data
using Edit > Replace.
1) Now, is it because i have given data validation on every cell in AGENTS
column and ERROR column to choose agents and the corresponding error they
had for the day, on all 31 sheets. and is it because i started entering data
from the 20th sheet onwards till date i.e. 26th, so it is not calculating
and giving the results (that is, count of Errors and sum of Time lost)
because of the starting blank sheets(and ending ones also)?

If you mean you're using data validation lists for AGENTS and ERROR columns, and
of the source lists contain stray trailing spaces, then that would be a possible
cause of your problems. ALWAYS ensure you eliminate trailing spaces. They seem
to be the single most frequent cause of text comparison errors in spreadsheets.
[They're a PITA in other software, but spreadsheet users and developers
generally have little experience handling arbitrary text, so this bites them in
the butts more often.]

However, if your source lists are clean or you're using a different form of
validation, then validation has no effect on other formulas. What's in the cells
is in the cells, and that's what other formulas use. Also, blank cells in
worksheets 01 to 19 and 27 to 31 shouldn't matter. Indeed, if you're getting
zeros rather than errors as results, at least the blank worksheets are being
counted correctly.
2) Also, since i have a cell e.g "A5" on every sheet (its actually a merged
cell that is, merged from A5 to C5) on top which gives me the most occuring
error for the day,

Merged cells could cause problems, but if your formulas access ranges with
topmost rows below row 5, this shouldn't cause any problems.
i use an Array formula for the error range C9:C69:

{=INDEX(C9:C69,MATCH(MAX(COUNTIF(C9:C69,C9:C69)),COUNTIF(C9:C69,C9:C69),0))}

to get the most occuring error for that day.

You could use a shorter, more efficient, non-array formula to do this.

=INDEX(C9:C69,MODE(MATCH(C9:C69,C9:C69,0)))

I believe Leo Heuser came up with this a few months ago (possibly earleir, but
that was the first time I'd seen it).
Please note, since 1st 19 sheets are empty, so the cell shows 0. after 20th,
the cell shows the error. now i made a named range, using your idea that is,
named,

WSE = "'"&WSLST&"'!B2"

Up above you mention A5, which is merged with B5 and C5, which you seem to say
contains the most frequent error on the particular worksheet, but the defined
name above uses B2. Which is it, A5 or B2? If it's A5, then your defined name
needs to refer to A5 rather than B2.
and used that in the final sheet to calculate the final error which occured
over the month that is, which occured maximum in the 31 sheets. BUT IT SHOWS
0. but when i entered some data in the 01st sheet, (that is, selected some
agents and some errors from the drop-down lists), i got the 1st error for
the day reflecting in the final sheet.

i used the array formula:

{=INDEX(INDIRECT(WSE),MATCH(MAX(COUNTIF(INDIRECT(WSE),INDIRECT(WSE))),
COUNTIF(INDIRECT(WSE),INDIRECT(WSE)),0))}
...

Won't work. The result from INDIRECT(WSE) can't be passed as first argument to
INDEX. It's good you're experimenting, but you need to recognize when your
experiments fail, *AND* you need to pay attention to the results from previous
experiments that worked.

You need to wrap anticipated numeric results from this sort of indirect
reference inside N() and anticipated text results inside T(). THESE ENCLOSING
FUNCTION CALLS ARE **NOT** OPTIONAL! I mentioned these in my original response
in this thread, but I may not have emphasized their necessity sufficiently. Now
I have.

Then use the simpler formula I suggested above, which now must be entered as an
array formula. [I suspect the reason array entry is now needed is due to the
fact that the first argument to INDEX is now the result of an expression rather
than a simple range reference.]

=INDEX(T(INDIRECT(WSE)),MODE(MATCH(T(INDIRECT(WSE)),T(INDIRECT(WSE)),0)))
Lastly, i am not able to understand, why you have taken the named range:

Seq = ROW(INDIRECT("1:20"), can i take it as ROW(INDIRECT("1:69") or
ROW(INDIRECT("9:69"), as my column range starts from the 9th row.

Note that if you're using Seq as second or third argument to OFFSET, the results
must be *OFFSETS* rather than *INDICES*. So to give pseudoreferences to C9, C10
and C11, you muse use

OFFSET($A$1,{8;9;10},2)

rather than

OFFSET($A$1,{9;10;11},3)

which would return pseudoreferences to D10, D11 and D12. So if you want rows 9
to 69, define Seq as =ROW(INDIRECT("8:68")) or use Seq-1 if you define Seq as
=ROW(INDIRECT("9:69")).
for WSBase = "'"&WSLST&"'!A1" , do i have to refer to the initial cell A1?
...

No, but I find it reduces errors in generalized dynamic ranges always to anchor
them at cell A1. You could define WSBase as ="'"&WSLST&"'!C9" , but you'd then
need to define Seq as =ROW(INDIRECT("1:61")) and use Seq-1 rather than Seq in
OFFSET. If that works for you, fine. [You'll learn.]
 
Back
Top