Want to always return the number of days between two cells...

hallingh

Well-known Member
Joined
Sep 11, 2010
Messages
769
So I have a fairly long piece of code, the result of which is always subracting one date from another. I want it to display the number of days between today and a certain date. Here is the code I'm using now:

Code:
Abs(Int(Now) - ActiveSheet.Range("K" & r).Value)

Sometimes this works, but a lot of the time it will display the number in date form. So if I want it to read "9" it will sometimes show 1/9/1900 or whatever the corresponding date would be in the Excel date index. Is there a way I can code it so it always shows the number of days between today and the date instead of showing the date from the Excel date index? I formatted the cell to general, but it still sometimes shows a date there instead of a number.

Any help you can provide me with is greatly appreciated.

Thanks!

Hank
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You could just change the cell format or maybe like this

Code:
Range("Z" & r).Value = CLng(Abs(Date - ActiveSheet.Range("K" & r).Value))
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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