Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default comparing two dates and executing code on condition

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.

  #2   Report Post  
Posted to microsoft.public.excel.misc
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.


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default comparing two dates and executing code on condition

Try:


Sub gsnu()
Dim d1 As Date
Dim d2 As Date
d1 = Date
d2 = "February 12,1997"
If d1 < d2 Then Exit Sub
MsgBox ("the date matches")
End Sub
--
Gary's Student


"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.


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default comparing two dates and executing code on condition

Thanks Alan, Your code worked and also thanks for keeping the point of
"Date format" in mind as i really forgot to mention it.
Thanks again
Alan wrote:
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.


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default comparing two dates and executing code on condition

Hi, <You have helped me twice but I dont know your name yet
I am thankful for your reply and solution but I opted Alan's
solution.
Hope to see u soon.

Gary''s Student wrote:
Try:


Sub gsnu()
Dim d1 As Date
Dim d2 As Date
d1 = Date
d2 = "February 12,1997"
If d1 < d2 Then Exit Sub
MsgBox ("the date matches")
End Sub
--
Gary's Student


"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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"