Validate Dates using VBA

tdahlman

New Member
Joined
Apr 11, 2014
Messages
14
I have a table ("Open Orders") with a column ("Date Paid"). If there is a date in the Date Paid column then I have a macro that removes that record from the table. What I want to do is use code that determines if any of the dates that have been entered are not equal to today's date. If they are all equal to today, then I want my current macro to continue to run and remove the record(s). If one or any of the dates are not equal to today, then I want a prompt that warns the user. I want the user to have the option to click continue or cancel. If the user clicks continue then I want the current code to continue running and then remove the records. If the user clicks cancel then the macro ends and he can check his entries.

I really appreciate any help on this.

Thanks
Travis
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
if date paid is column D then u can do something like

Code:
Sub CheckDates()
Dim iRow As Integer
iRow = Range("D:D").Find("*", , , , xlByRows, xlPrevious).Row
If CBool(Evaluate(Replace("COUNTIF(D2:D@, ""<>"" & today())", "@", iRow))) Then
    If MsgBox("Do you wanna continue anyway?", vbYesNo) = vbYes Then Call mymacro Else: Exit Sub
Else
    Call mymacro
End If
End Sub


Sub mymacro()
' your main macro here
    MsgBox "hi"
End Sub
 
Upvote 0
This is really close. Right now when I run this I get the message box regardless of which dates are entered. I think that the problem is most of the cells in the Date Paid column are blank, so it may be triggering the message box. I need to the code to ignore blank cells.

Thank you very much!
Travis


if date paid is column D then u can do something like

Code:
Sub CheckDates()
Dim iRow As Integer
iRow = Range("D:D").Find("*", , , , xlByRows, xlPrevious).Row
If CBool(Evaluate(Replace("COUNTIF(D2:D@, ""<>"" & today())", "@", iRow))) Then
    If MsgBox("Do you wanna continue anyway?", vbYesNo) = vbYes Then Call mymacro Else: Exit Sub
Else
    Call mymacro
End If
End Sub


Sub mymacro()
' your main macro here
    MsgBox "hi"
End Sub
 
Upvote 0
Code:
Sub CheckDates()
Dim iRow As Integer
iRow = Range("D:D").Find("*", , , , xlByRows, xlPrevious).Row
If CBool(Evaluate(Replace("COUNTIF(D2:D@,TODAY())<>ROWS(D2:D@)", "@", iRow))) Then
    If MsgBox("Do you wanna continue anyway?", vbYesNo) = vbYes Then Call mymacro Else: Exit Sub
Else
    Call mymacro
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,579
Messages
6,131,531
Members
449,654
Latest member
andz

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