Macro to determine if morning process or Afternoon Process

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Macro to determine if morning process or Afternoon Process

Post by chamdan »

Hi Hans or Rudi,

I need a macro that will check whether to process a morning macro or an afternoon macro.

e.g.: If the time is less than 12:00:00 PM then process macro "A", else process macro "B"

I could not figure out how to check the time?

Regards,

Chuck

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Macro to determine if morning process or Afternoon Proce

Post by HansV »

For example like this:

Code: Select all

    If Hour(Now) < 12 Then
        Call MorningMacro
    Else
        Call AfternoonMacro
    End If
Best wishes,
Hans

User avatar
chamdan
3StarLounger
Posts: 372
Joined: 17 Dec 2013, 00:07

Re: Macro to determine if morning process or Afternoon Proce

Post by chamdan »

:thankyou: Hans,

I had done some test and finally got it done. I created a sample as shown below and worked as well.

Code: Select all

Dim thisTime As Date
thisTime = Time
If Right(thisTime, 2) = "AM" Then
MacroA
Else
MacroB
End If