macro to compute average

Eric Kelcher

Board Regular
Joined
May 11, 2006
Messages
129
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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Dufus

Board Regular
Joined
Aug 19, 2006
Messages
176
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!"
 

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
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
 

GorD

Well-known Member
Joined
Jan 17, 2004
Messages
1,446
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
 

eliW

Well-known Member
Joined
Mar 2, 2002
Messages
1,934
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
 

Eric Kelcher

Board Regular
Joined
May 11, 2006
Messages
129
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
 

Forum statistics

Threads
1,141,707
Messages
5,707,979
Members
421,539
Latest member
zuniBM

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
Top