macro to compute average

Eric Kelcher

Board Regular
Joined
May 11, 2006
Messages
130
I need a macro to compute the average for cells that have an unknown range. I am having an issue as the cells to compute the average of have a formula in them and if there is no data for that formula it is dividing by zero thus #DIV/0! So how do I make a macro figure the cells that have real data in them? or better how do I get the formula to appear if there is values in the relevant cells. (fairly uniform (b2-b3+1)/b3, (c2-c3+1)/c3...) then I want allt he cells that have formula in them to be averaged.

I thought I had it figured out to compute how many cells had info in them but the #DIV/0 threw me for a loop, and miscalculated.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Eric Kelcher,

I couldn't quite decipher all the question but I'll offer this in hopes it helps. A common way to handle divide by zero errors is:
Code:
=IF(C3=0,0,(c2-c3+1)/c3)

Dufus
"Go Cowboys!"
 
Upvote 0
Perhaps change the formula to

=if(b3,(b2-b3+1)/b3,"")

then if b3 is blank or zero the formula will generate a blank which won't be included in your average
 
Upvote 0
Try

=AVERAGE(IF(ISNUMBER(L3:L12),L3:L12))

which is an array formula, so enter with ctrl shift enter rather than just enter.

Obviously change the range to suit your data
 
Upvote 0
Hi

You may also use a formula that ignors the cells with any error:

=AVERAGE(IF(NOT(ISERROR(B1:E1)),B1:E1))

Asuming your cells are B1:E1

This is an array formula so enter with ctrl+ shift+ enter

Eli
 
Upvote 0
Hi

You may also use a formula that ignors the cells with any error:

=AVERAGE(IF(NOT(ISERROR(B1:E1)),B1:E1))

Asuming your cells are B1:E1

This is an array formula so enter with ctrl+ shift+ enter

Eli

That did it thanks
 
Upvote 0

Forum statistics

Threads
1,214,377
Messages
6,119,182
Members
448,872
Latest member
lcaw

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