Triggering macro between different halves of year

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hey all,

I am just trying to sort out some code which needs to trigger between different halves of the year. It does not matter what year or day of the month. Any date before 31 June trigger one way and any date after 1 July trigger another way. I have tried many different versions of date and Month but cannot get it to work.

VBA Code:
If "todays date = June or less" Then ' first code goes here

If "todays date = July or more" Then 'second code goes here

Cheers,
Milos
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Rich (BB code):
Sub TestTodaysDate()
' VBA DATE function is equivalent of TODAY() in Excel

    If Month(Date) < 7 Then
        MsgBox "today is in 1st half of year"
    Else
        MsgBox "today is in 2nd half of year"
    End If
End Sub

Sub TestDateInCell()

    If Month(Range("A1")) < 7 Then
        MsgBox "1st half of year"
    Else
        MsgBox "2nd half of year"
    End If
End Sub
 
Upvote 0
Thanks Yongle,

Okay I did have it correct. My code was incorrect elsewhere.. I have figured about what I was doing wrong I was trying to incorporate 2 rules into an If statement and was using '&' rather than 'And' which seemed to be causing an error without causing an error per se.

Cheers again,
Milos
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,941
Members
448,534
Latest member
benefuexx

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