VBA Subtracting dates

knacksc2

Board Regular
Joined
Jan 23, 2014
Messages
63
I am creating a report from a data file. I want to drop the difference in days from the date in column 11 from today into column 13. this seems like it should work...

Code:
Sub Printed_Not_Packed()


Dim FPathIM As String
Dim FPathBIA As String
Dim FPathIOS As String


FPathIM = "U:\Inventory Management\"
FPathBIA = "U:\Inventory Management\Branch Inventory Analysis\"
FPathIOS = "U:\Inventory Management\Interbranch Orders status\"


FName1 = Format(Date, "YYYYMMDD") & " ~~~~~~~~~~~~~~Printed and Not Packed" & ".xlsx"






Workbooks.Open Filename:="U:\Inventory Management\Printed and Not Packed.XLS"
ActiveWorkbook.SaveAs Filename:=FPathIM & FName1 _
    , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False


Workbooks(FName1).Activate


ActiveSheet.Cells(1, 13).Value = "AGE"
ActiveSheet.Cells(1, 14).Value = "OVER 7 DAYS"
ActiveSheet.Cells(1, 15).Value = "ORDER QTY OVER 7 DAYS"


For i = 1 To 65000
Workbooks(FName1).Worksheets("Sheet1").Cells(1 + i, 13).Value = (DateValue(DateSerial(Year(Now()), Month(Now()), Day(Now())))) - DateValue(Workbooks(FName1).Worksheets("Sheet1").Cells(1 + i, 11).Value) - 1
Next i
 

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.
i think i solved this, but i am not sure why... this seems to be working

Code:
ActiveWorkbook.Worksheets("Sheet1").Cells(1 + i, 13).Value = (DateValue(DateSerial(Year(Now()), Month(Now()), Day(Now())))) - DateValue(ActiveWorkbook.Worksheets("Sheet1").Cells(1 + i, 11).Value) - 1

also, there may have been one row missing a value, that could cause the error, but it should repeat all the way up to the point where the blank occurs. so... yeahstillnot sure why it wouldn't work.
 
Upvote 0
One little tip.

I think this whole part:
Code:
(DateValue(DateSerial(Year(Now()), Month(Now()), Day(Now()))))
can simply be replaced with this:
Code:
Date
which returns the current date (with no time component)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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