Need a formula for finding average only if greater than 0

Julesdude

Board Regular
Joined
Jan 24, 2010
Messages
197
Hello all,

I was wondering if there was a particular command to do the following:
I have a master workbook which links to 12 individual workbooks by month.
Is there a formular which allows me to find the mean average of the totals for the specified cells in each workbook, but if an amount in one workbook is 0 then it will discard it.

For example:
12 workbooks for each month
11 have a value in referenced cell that is greater than 0
Divide SUM of those 12 workbooks by 11
= the average

Is there a formula that will do this?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hello all,

I was wondering if there was a particular command to do the following:
I have a master workbook which links to 12 individual workbooks by month.
Is there a formular which allows me to find the mean average of the totals for the specified cells in each workbook, but if an amount in one workbook is 0 then it will discard it.

For example:
12 workbooks for each month
11 have a value in referenced cell that is greater than 0
Divide SUM of those 12 workbooks by 11
= the average

Is there a formula that will do this?

=IF(F15>0,AVERAGE(A:A),"")

Change the cell references as required
 
Upvote 0
Hi TiaXL, thanks for that. Is there perhaps a more refined way of writing that formula? I ask because to check that the cells are greater than 0 I would need to reference 12 sheets for the IF statement and then 12 sheets again for the AVERAGE statement.
 
Upvote 0
Hi TiaXL, thanks for that. Is there perhaps a more refined way of writing that formula? I ask because to check that the cells are greater than 0 I would need to reference 12 sheets for the IF statement and then 12 sheets again for the AVERAGE statement.

do it with VBA

open each workbook. check value of the cell and use an IF statement to define what you want to do if the value is true/false
 
Upvote 0
Hi TiaXL, thanks for that. Is there perhaps a more refined way of writing that formula? I ask because to check that the cells are greater than 0 I would need to reference 12 sheets for the IF statement and then 12 sheets again for the AVERAGE statement.
Can I ask whether you mean workbooks or sheets within a single workbook? You seem to be using both terms.
 
Upvote 0
workbooks, you said you had 12 individual workbooks.

do workbooks.open for each workbook

select sheet in each workbooks

check reference cell as above.

use IF statement to determine what to do and then use formula above to get the figure you want and put it where you want it to go

for example

Code:
sub workbooks()
 
 
workbooks.open("Jan.xls")
Sheets("Sheet1").select
range("f10").select
 
if activecell.value >0 then
  range("F18").SELECT
  ACTIVECELL.FORMULA = "=AVERAGE(A:A)"
  workbooks.("Main").Sheets("Sheet1").range("AB1").VALUE = ACTIVECELL.VALUE
end if
 
next workbook

You can do it like this or loop through each sheet and do it that way (which is better as less code)
 
Upvote 0
Sorry Glenn, yes I meant workbooks - I need to reference a sheet in each of the 12 workbooks.

I was hoping to avoid VBA code and have a macro free master sheet and just have a formula with the 12 links to monthly workbooks. Guess it is a bit too complex for that though. Thing is it would be just as complex for the VBA code too as other cells also have to draw on 12 workbooks. We're actually talking about over 100 cells which reference these and then try to draw an average.
 
Upvote 0
Sorry Glenn, yes I meant workbooks - I need to reference a sheet in each of the 12 workbooks.

I was hoping to avoid VBA code and have a macro free master sheet and just have a formula with the 12 links to monthly workbooks. Guess it is a bit too complex for that though. Thing is it would be just as complex for the VBA code too as other cells also have to draw on 12 workbooks. We're actually talking about over 100 cells which reference these and then try to draw an average.

Bring your required data into ranges by doing single cell links, and then do formulas on the linked data, rather than trying to do formulas with embedded links in.
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,391
Members
452,909
Latest member
VickiS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top