# need a formula

#### jpross

##### New Member
I have a cell with at Start date, another cell with a stop date and, aformula to calculate the number of days between them - no problem. When there is a date in the start date cell BUT no date (blank) in the stop cell the cell containing the formula returns #NUM!. HOW DO I get the cell t oreturn a zero (0)?

### Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

#### Dave Patton

##### Well-known Member
On 2002-10-16 14:18, jpross wrote:
I have a cell with at Start date, another cell with a stop date and, aformula to calculate the number of days between them - no problem. When there is a date in the start date cell BUT no date (blank) in the stop cell the cell containing the formula returns #NUM!. HOW DO I get the cell t oreturn a zero (0)?

What formula are you using?

consider

=((B3>0)*(B3-A3))

#### jpross

##### New Member
I'm usingthe formula DATEDIF(a1,a2,"D")

##### MrExcel MVP
On 2002-10-16 14:30, jpross wrote:
I'm usingthe formula DATEDIF(a1,a2,"D")

=IF(COUNTBLANK(A1:A2),0,DATEDIF(A1,A2,"D"))

You can substitute A2-A1 for DATEDIF(A1,A2,"D") in the above formula.

#### jpross

##### New Member
So, how do I add an if statement to that formula that will cause the answer to be 0 when a2 is blank.

#### Barry Katcher

##### Well-known Member
Dave's formula works fine, but I don't understand why yours doesn't. What formula are you using? When I use a simple =A1-B1 (Stop - Start), and I have nothing entered in A1, I get a negative of the number of days from 1/1/1900 to the start date (ex: null minus 6/30/2002 equals -37,437), I do not get an error message.

#### Barry Katcher

##### Well-known Member
In answer to how to show zero if no stop date, and assuming A1 is start date, B1 is stop date, and C1 is the number of days between, in C1 use either:

=IF(B1="",0,B1-A1)
or
=IF(B1-A1<0,0,B1-A1)

##### MrExcel MVP
On 2002-10-16 14:38, jpross wrote:
So, how do I add an if statement to that formula that will cause the answer to be 0 when a2 is blank.

That formula will give you a 0, whenever A1 or A2 or both cells are empty.

#### jpross

##### New Member
Aladin's formula worked perfectly. Thanks a bunch!!!

Replies
5
Views
143
Replies
0
Views
336
Replies
3
Views
169
Replies
3
Views
167
Replies
2
Views
148

1,181,531
Messages
5,930,432
Members
436,738
Latest member
JFry

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