Const dtEarliest formula help

emoandy05

Board Regular
Joined
Sep 4, 2013
Messages
60
Hey,

I have the following formula:

Const dtEarliest = "11/20/2015"

How to I set the date in the parenthesis to automatically be today's date minus 10 days?


Thank you.

Emerson
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
As a Const, you can't.
But you can dim dtEarliest as Date and in the open routine you can set it:

Private Sub Workbook_Open()
dtEarliest = Date - 10
End Sub

and in a regular module:
Public dtEarliest As Date
 
Upvote 0
this is my full code.... would this work?

Code:
Dim dtTestDate As Date
    Dim sStartWB As String
    Public dtEarliest As Date
    
    Const sPath As String = "Z:\Report\"
    dtEarliest = now()-10


    dtTestDate = Date
    sStartWB = ActiveWorkbook.Name
    
    While ActiveWorkbook.Name = sStartWB And dtTestDate >= dtEarliest
        On Error Resume Next
        Workbooks.Open sPath & Format(dtTestDate, "MM.DD.YYYY") & " Report.xlsx"
        dtTestDate = dtTestDate - 1
        On Error GoTo 0
    Wend
    
    If ActiveWorkbook.Name = sStartWB Then MsgBox "Earlier file not found."
 
Upvote 0
So that does work, thanks for your help! I do get a message though until my macro finds a matching date. To dismiss it, i have to click ok, and it proceeds to the next date. Any way to remove the notification?
 
Upvote 0
So that does work, thanks for your help! I do get a message though until my macro finds a matching date. To dismiss it, i have to click ok, and it proceeds to the next date. Any way to remove the notification?

this works: Application.DisplayAlerts = False

Thanks.
 
Upvote 0

Forum statistics

Threads
1,216,166
Messages
6,129,260
Members
449,497
Latest member
The Wamp

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