# macro to compute average

#### Eric Kelcher

##### Board Regular
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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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!"

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

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

Hi

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

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

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

Eli

Hi

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

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

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

Eli

That did it thanks

Replies
3
Views
346
Replies
1
Views
251
Replies
3
Views
264
Replies
2
Views
322
Replies
4
Views
292

1,217,328
Messages
6,135,919
Members
449,972
Latest member
Natejack

### 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.

### Which adblocker are you using?

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

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