#DIV/0! error when cells are blank

RutlandPuritan

New Member
Joined
Nov 8, 2016
Messages
3
Hello.

I have a timetable on Excel. The first worksheet is organized into blocks of different activities.

For each activity there are staff members and participants listed.

On the second worksheet, I use formulae like this one:

=((COUNTIF(Mon!$B$9:$B$14,A4)*$B$2)/COUNTIF(Mon!$B$5:$B$7,"*")/COUNTIF(Mon!$B$9:$B$14,"*"))

So if, for example, Fred's name is in A4, it will give the number of hours as defined in B2. It will then divide this by the number of staff and the number of participants (i.e. if any text is the specified range) to give the total support hours.

This works fine except if (in this instance) B9:B14 and B5:B7 are blank. It then produces a #DIV/0! error.

This is a problem because the cell adds up for all of the activity blocks and looks like this:

=((COUNTIF(Mon!$B$9:$B$14,A4)*$B$2)/COUNTIF(Mon!$B$5:$B$7,"*")/COUNTIF(Mon!$B$9:$B$14,"*"))
+((COUNTIF(Mon!$B$19:$B$24,A4)*$B$2)/COUNTIF(Mon!$B$17,"*")/COUNTIF(Mon!$B$19:$B$24,"*"))
+((COUNTIF(Mon!$B$30:$B$36,A4)*$B$2)/COUNTIF(Mon!$B$27:$B$28,"*")/COUNTIF(Mon!$B$30:$B$36,"*"))
+((COUNTIF(Mon!$B$42:$B$47,A4)*$B$2)/COUNTIF(Mon!$B$39:$B$40,"*")/COUNTIF(Mon!$B$42:$B$47,"*"))
+((COUNTIF(Mon!$B$42:$B$47,A4)*$B$2)/COUNTIF(Mon!$B$39:$B$40,"*")/COUNTIF(Mon!$B$42:$B$47,"*"))...

Sometimes certain activity blocks will be empty and others, which were empty, filled in. I want this formula to give me the results without having to change it all the time.

So what I would like Excel to do is ignore one range of cells if it is blank, but still continue to add up the others which are not blank.

Is this achievable?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
You can use IFERROR on each formula to return zero if there is an error.
Code:
=IFERROR((COUNTIF(Mon!$B$9:$B$14,A4)*$B$2)/COUNTIF(Mon!$B$5:$B$7,"*")/COUNTIF(Mon!$B$9:$B$14,"*"),0)
 +IFERROR((COUNTIF(Mon!$B$19:$B$24,A4)*$B$2)/COUNTIF(Mon!$B$17,"*")/COUNTIF(Mon!$B$19:$B$24,"*"),0)
 +IFERROR((COUNTIF(Mon!$B$30:$B$36,A4)*$B$2)/COUNTIF(Mon!$B$27:$B$28,"*")/COUNTIF(Mon!$B$30:$B$36,"*"),0)
 +IFERROR((COUNTIF(Mon!$B$42:$B$47,A4)*$B$2)/COUNTIF(Mon!$B$39:$B$40,"*")/COUNTIF(Mon!$B$42:$B$47,"*"),0)
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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