MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Aug 19th, 2003, 09:34 PM   #1
unclehighbrow
 
Join Date: Aug 2003
Posts: 5
Default non-contiguous non-zero sum averages

I've been trying to averages without zero values, and that was pretty easy, I found a number of solutions that worked perfectly. Although when I try to make those solutions work with non-contiguous cells, i.e., =AVERAGE(IF(H3,I3,M3,P3,P4,S3)) instead of =AVERAGE(IF(H3:H12)) I either get a #VALUE or just an Excel 'you did something wrong' dialog. Anybody get what I'm talking about? Is this as easy as it seems like it should be?

Thanks
unclehighbrow
unclehighbrow is offline   Reply With Quote
Old Aug 19th, 2003, 09:46 PM   #2
Joe4
MrExcel MVP
Moderator
 
Joe4's Avatar
 
Join Date: Aug 2002
Posts: 14,220
Default Re: non-contiguous non-zero sum averages

Check out the various replies in this thread. There are many more, if you use the Search functionality on this web site.

http://www.mrexcel.com/board2/viewto...ight=averageif
__________________
TIPS FOR FINDING EXCEL SOLUTIONS
1. Use the built-in Help that comes with Excel/Access
2. Use the Search functionality on this board
3. A lot of VBA code can be acquired by using the Macro Recorder.
Joe4 is offline   Reply With Quote
Old Aug 19th, 2003, 09:46 PM   #3
GaryB
 
Join Date: Feb 2002
Location: Essex, England
Posts: 456
Default

I may be misunderstanding you, but wouldn't =AVERAGEA((H3,I3,M3,P3,P4,S3) do what you want?

GaryB
GaryB is offline   Reply With Quote
Old Aug 19th, 2003, 09:54 PM   #4
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 39,494
Default Re: non-contiguous non-zero sum averages

=AVERAGE(IF(LARGE(NCrange,ROW(INDIRECT("1:"&COUNT(NCrange)))),LARGE(NCrange,ROW(INDIRECT("1:"&COUNT(NCrange))))))

which must be array-entered, that is, you need to hit control+shift+enter at the same time, not just enter.

NCrange is the name that you type in the Name Box after pressing and holding down control key while selecting all relevant non-consecutive cells.
Aladin Akyurek is offline   Reply With Quote
Old Aug 19th, 2003, 10:29 PM   #5
unclehighbrow
 
Join Date: Aug 2003
Posts: 5
Default Re: non-contiguous non-zero sum averages

Yeah, I'm probably not being that clear. AVERAGEA doesn't work for me because it doesn't ignore zero values. And that link to another thread kind of left me more confused than I already am. Before, when I needed to get the ignoring zero averages, I'd have a hidden cell that had the count of the column, that went like

=COUNTIF(R3:R24, ">0")

and then just used that to divide the sum of the row. But doing this, that is, averaging non-contiguous cells:

=COUNTIF(R3,R24,R30, ">0")
or
=COUNTIF((R3,R24,R30), ">0")

messes it up
unclehighbrow is offline   Reply With Quote
Old Aug 19th, 2003, 11:06 PM   #6
unclehighbrow
 
Join Date: Aug 2003
Posts: 5
Default Re: non-contiguous non-zero sum averages

Oh, and I didn't read Aladin's post before I replied. That's a damn fine piece of excel work there, but if I have to go to all the trouble of setting up names for every group, I might as well just go through and just pick out all the non-zero values and stick them in an average, you know? So do I still have a problem or is it that I just don't understand the solutions given to me. Or both?

Thanks
unclehighbrow
unclehighbrow is offline   Reply With Quote
Old Aug 19th, 2003, 11:12 PM   #7
NateO
MrExcel MVP
Admin
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,617
Default Re: non-contiguous non-zero sum averages

Hello,

Didn't we decided that the following's a good way to do this:

http://www.mrexcel.com/board2/viewto...58360&start=10

?
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old Aug 19th, 2003, 11:20 PM   #8
PaddyD
MrExcel MVP
 
Join Date: May 2002
Posts: 12,561
Default Re: non-contiguous non-zero sum averages

"That's a damn fine piece of excel work there, but if I have to go to all the trouble of setting up names for every group, I might as well just go through and just pick out all the non-zero values and stick them in an average, you know"


Perhaps, although nameing them might save you time if you had to operate on the same set of non-contiguous rangtes a lot. In any event, either there is a regularity about the cells you want to pick (every third column, for example), or you'll have to define them explicitly, whether with names or range references.
PaddyD is offline   Reply With Quote
Old Aug 20th, 2003, 12:53 PM   #9
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 39,494
Default Re: non-contiguous non-zero sum averages

Quote:
Originally Posted by PaddyD
"That's a damn fine piece of excel work there, but if I have to go to all the trouble of setting up names for every group, I might as well just go through and just pick out all the non-zero values and stick them in an average, you know"


Perhaps, although nameing them might save you time if you had to operate on the same set of non-contiguous rangtes a lot. In any event, either there is a regularity about the cells you want to pick (every third column, for example), or you'll have to define them explicitly, whether with names or range references.
My reply assumes/pre-supposes indeed an irregularly spaced non-contiguous set of cells/ranges. If there is any regularity in spacing, then formulas exploiting such regularity should be used instead.
Aladin Akyurek is offline   Reply With Quote
Old Aug 20th, 2003, 03:14 PM   #10
unclehighbrow
 
Join Date: Aug 2003
Posts: 5
Default Re: non-contiguous non-zero sum averages

All right, get this:

=IF( OR(H9,I9,M9,P9,S9),(H9+I9+M9+P9+S9)/(IF(AND(H9<>0),1,0)+IF(AND(I9<>0),1,0)+IF(AND(M9<>0),1,0)+IF(AND(P9<>0),1,0)+IF(AND(S9<>0),1,0)), 0)

Kind of unweildy, but I guess that's how it has to be.

Thanks for everyone's help

unclehighbrow
unclehighbrow is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 04:21 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.