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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,074
Messages
6,128,649
Members
449,462
Latest member
Chislobog

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