View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Alan Alan is offline
external usenet poster
 
Posts: 138
Default comparing two dates and executing code on condition

Try:

Sub test()

Dim dDate As Date
Const aDate As Date = "8/30/2006"
dDate = Format(Now(), "MM/DD/YYYY") 'the test date

If dDate = aDate Then
MsgBox "Dates match - do this code"
Else
End
End If

End Sub


ashish128 wrote:
Hello All,
I have a macro which works perfectly but I want to add a condtion
which will compare the current system date with a date (a static date
written in code itself so no dynamics required). If the dates are same
then the code should run further else it should terminate my macro.

I dont have knowledge of VBA so please detail the process to wrap my
existing macro into a Condition.
In C/C++ I would have written
if(today()=8/30/2006) //////// Please ignore syntax faults if any.
{
execute true code // current macro code
}

Please help.