Help with Function Procedure?

Lalo2DaG

New Member
Joined
Oct 8, 2015
Messages
8
I download a report every day. This report tells me how olda certain product will be by a future date. For my purposes, I have to then adda column and do a quick calculation. My calculation is as follows: Future date –Todays date = number of days. <o:p></o:p>
For example, the product future date is 10/1/2017 and todaysdate is 11/30/2016. 10/1/2017 – 11/30/2016= 305 days.<o:p></o:p>
I have been trying to find a way to write code to do thisfor me, preferably without having to add an extra column. I think it should be a functionprocedure. The column on the excel sheetis “AF”. I hope I made my question clearand not overly confusing. But any help would be greatly appreciated. Thank you.<o:p></o:p>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
If you don't want an extra column, how would you like this information to be presented to you?
 
Upvote 0
something like this:
Code:
Sub NumDaysToFutureDate()
Dim rng As Range, cell As Range, FutureDate As Variant
Application.ScreenUpdating = False
Set rng = Range("AF1", Cells(Rows.Count, "AF").End(xlUp))
For Each cell In rng
    On Error Resume Next
    FutureDate = CDate(cell.Value)
    On Error GoTo 0
    If FutureDate > Date And VarType(FutureDate) = vbDate Then cell.Value = FutureDate - Date
Next cell
rng.NumberFormat = "0"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,801
Messages
6,121,644
Members
449,045
Latest member
Marcus05

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