Input date if Date + 30 days < current month and year

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have the following code below


I would like the input box to appears to input the date only if the date in A3 on sheet BR1 +30 < date
, otherwise exit sub

It would be appreciated if someone could amend my code


Code:
  Sub Date_Input()
Sheets("Sales").Select
Dim MyDate As String
Range("a3").Select
If Range("A3") + 30 > Now() Then
Exit Sub
Else
End If

ActiveCell.FormulaR1C1 = InputBox("Enter the current Month and year for eg June 2006")

Sheets(1).Select
End Sub
 

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.
So, are you trying to replace the existing value in cell A3 with that condition is met?

Do you realize that if you just enter the month and year of a date, it will automatically assign a day value of "1" to that date?
Is that OK?

How is this code being called to run?
 
Upvote 0
Hi Joe

I have an existing date in A3 (format dd/mm/yyyy). If A3 is say 30/04/2019 + 30 days is 30/05/2019 and the current date is 21/05/2019 then date not to change i.e exit sub, otherwise date to be inputted using inputbox to change the date in A3
 
Upvote 0
But you mention two sheets, "BR1" and "Sales". Your description and code seem to conflict with each other.
Which sheet are you checking the date on?
Which sheet are you wanting to update?
 
Upvote 0
My Apologies Joe

Just saw my typo now.

Sheet BR1 should sheet "Sales"
 
Upvote 0
Try this. I added a loop, so it will keep asking for a date until a valid one is entered (in case the make a typo).
Code:
Sub Date_Input()

    Dim MyDate As Variant
    Dim updated As Boolean

'   Initialize variable
    updated = False

    If Sheets("Sales").Range("A3") + 30 > Date Then
        Exit Sub
    Else
        Do Until updated = True
'           Ask for date
            MyDate = InputBox("Enter the current Month and year for eg June 2006")
'           Check for valid date
            If IsDate(MyDate) Then
                Sheets("Sales").Range("A3") = MyDate
                updated = True
            End If
        Loop
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,748
Messages
6,180,721
Members
452,995
Latest member
isldboy

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