# 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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

#### Dufus

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

Replies
3
Views
270
Replies
7
Views
283
Replies
1
Views
82
Replies
1
Views
466
Replies
4
Views
142

Threads
1,141,705
Messages
5,707,976
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

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