How to do COUNTIF when cells are not in a consequtive column?

K

Karin

I would like to average an array of cells, but only include those cells whose
cell value is greater than zero.
I have an array like (D3;G3;J3), and want to include only those
AVERAGE(D3;G3;J3). I have tried to use
SUM(D3;G3;J3)/COUNTIF((D3;G3;J3);">0" )
but the COUNTIF doesn't allow that arrayform (D3;G3;J3). If I for example
put COUNTIF((D3:D7);">0") , that works - but that's not the cells where my
data is!
How should I write the array so that it works?
Yours
Karin
 
M

Mike H

Hi,

Try this

=AVERAGE(IF(ISNUMBER(MATCH(COLUMN(A3:J3),{4,7,10},0))*(A3:J3>0),A3:J3))

'This is an array formula which must be entered by pressing CTRL+Shift+Enter
'and not just Enter. If you do it correctly then Excel will put curly brackets
'around the formula {}. You can't type these yourself. If you edit the formula
'you must enter it again with CTRL+Shift+Enter.

Mike
 
B

Bernard Liengme

This will average non-zero cells: =SUM(D3,G3,J3)/SUM((D3>0)+(G3>0)+(J3>0))
Note that negative values will give an incorrect answer
This will average only positive values and ignore negative and zero values
=SUM(D3*(D3>0),G3*(G3>0),J3*(J3>0))/SUM((D3>0)+(G3>0)+(J3>0))
Convert commas (,) to semicolons (;) for you local version of Excel
best wishes
 
V

vezerid

I noticed that your cells are spaced equally, every third column. Thus
you can use the following *array* formula

=AVERAGE(IF((D3:Z3>0)*(MOD(COLUMN(D3:Z3),3)=1),D3:Z3)

Commit with Shift+Ctrl+Enter

HTH
Kostis Vezerides
 
K

Karin

Thanks to all of you, I think all of your suggestions worked fine! Problem
solved!
Karin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top