Can I create a "Button" on a sheet that only becomes visible in the month of Jun?

mikecox39

Active Member
Joined
Mar 5, 2014
Messages
251
Office Version
  1. 365
Platform
  1. Windows
Every year, in June, I create a new workbook from the current workbook.

I have a macro the does all that and I put a button on the current workbook to run it, but I want to hide it until Jun, so no one will hit it mistake. Can that be done?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Paste below code in your June Code Sheet (Code below currently reads Sheet1). Currently assumes your Command button to be named "CommandButton1". You will only need to edit it each year to update the year in the code dates. HTH, Jim

Code:
Private Sub Worksheet_Activate()
'ActiveX button
If Date >= DateValue("6/01/2019") And Date <= DateValue("6/30/2019") Then
  Sheets("Sheet1").CommandButton1.Visible = False
Else
  Sheets("Sheet1").CommandButton1.Visible = True
End If
End Sub
 
Upvote 0
Paste below code in your June Code Sheet (Code below currently reads Sheet1). Currently assumes your Command button to be named "CommandButton1". You will only need to edit it each year to update the year in the code dates. HTH, Jim

Code:
Private Sub Worksheet_Activate()
'ActiveX button
If Date >= DateValue("6/01/2019") And Date <= DateValue("6/30/2019") Then
  Sheets("Sheet1").CommandButton1.Visible = False
Else
  Sheets("Sheet1").CommandButton1.Visible = True
End If
End Sub


Awsome! Thanks to much!

But here's the rub... I'm turning this WB over to someone who, most likely, will not know how to edit a macro.
Is it possible to code it so it updates itself, based on the current date? So it updates itself at the time is it used?
 
Upvote 0
Maybe something like this...

Code:
Private Sub Worksheet_Activate()
'ActiveX button
dYear = Year(Date) 'your systems currrent year
If Date >= DateSerial(dYear, 6, 1) And Date <= DateSerial(dYear, 6, 30) Then
    Sheets("Sheet1").CommandButton1.Visible = False
Else
  Sheets("Sheet1").CommandButton1.Visible = True
End If
End Sub
 
Upvote 0
Maybe something like this...

Code:
Private Sub Worksheet_Activate()
'ActiveX button
dYear = Year(Date) 'your systems currrent year
If Date >= DateSerial(dYear, 6, 1) And Date <= DateSerial(dYear, 6, 30) Then
    Sheets("Sheet1").CommandButton1.Visible = False
Else
  Sheets("Sheet1").CommandButton1.Visible = True
End If
End Sub
I think this Activate event code (same sheet and button as you assumed) will also work...
Code:
Private Sub Worksheet_Activate()
  Sheets("Sheet1").CommandButton1.Visible = Month(Now) = 6
End Sub
 
Last edited:
Upvote 0
I think this Activate event code (same sheet and button as you assumed) will also work...
Code:
Private Sub Worksheet_Activate()
  Sheets("Sheet1").CommandButton1.Visible = Month(Now) = 6
End Sub

This looks super simple. Even I understand it, i think.

It looks me like the button will appear on the current worksheet every year, for the entire month of Jun, with no need to update it. If that's correct "I love it"!
 
Upvote 0
This looks super simple. Even I understand it, i think.

It looks me like the button will appear on the current worksheet every year, for the entire month of Jun, with no need to update it. If that's correct "I love it"!
I am not sure "current worksheet" is the proper term. What I posted is event code and event code goes in the code sheet for a particular worksheet, not any worksheet that is active. To install the code I posted, you must right click the tab for the worksheet you want to put the code in... a code window will open... you copy/paste my code in it. Then after that, whenever that worksheet activates, the code I posted will run... it will test to see if the current month number is 6 and, if it is, the Month(Now)=6 part of the code line will evaluate to True which, in turn, will be assigned to the CommandButton's Visible property... if the month number is not 6, then False will be assigned to the CommandButton's Visible property.
 
Last edited:
Upvote 0
I am not sure "current worksheet" is the proper term. What I posted is event code and event code goes in the code sheet for a particular worksheet, not any worksheet that is active. To install the code I posted, you must right click the tab for the worksheet you want to put the code in... a code window will open... you copy/paste my code in it. Then after that, whenever that worksheet activates, the code I posted will run... it will test to see if the current month number is 6 and, if it is, the Month(Now)=6 part of the code line will evaluate to True which, in turn, will be assigned to the CommandButton's Visible property... if the month number is not 6, then False will be assigned to the CommandButton's Visible property.

The sheet i would put this in would be sheets("Master")

I'm taking a course in VBA so I'm a real novice, which means I'm not certain where to put this.

I could put it in a module but I'm thinking that putting in the master sheet Object might be better since I wouldn't use it on any other sheet or in any other WB. In that case would the Worksheet("Master") be needed but could you just put the method (or property, I still have trouble with syntax)?
 
Last edited:
Upvote 0
The sheet i would put this in would be sheets("Master")

I'm taking a course in VBA so I'm a real novice, which means I'm not certain where to put this.

I could put it in a module but I'm thinking that putting in the master sheet Object might be better since I wouldn't use it on any other sheet or in any other WB. In that case would the Worksheet("Master") be needed but could you just put the method (or property, I still have trouble with syntax)?
You must put my code in the worksheet's code module... nowhere else. Again, right-click the tab for your "Master" worksheet and select "View Code" from the popup menu that appears, then copy/paste my code into that code window. That's it... you are done. From then on out, whenever the "Master" worksheet is activated, the code I gave you will run (and display the CommandButton on in the 6th month).
 
Upvote 0
You must put my code in the worksheet's code module... nowhere else. Again, right-click the tab for your "Master" worksheet and select "View Code" from the popup menu that appears, then copy/paste my code into that code window. That's it... you are done. From then on out, whenever the "Master" worksheet is activated, the code I gave you will run (and display the CommandButton on in the 6th month).
Ok, thanks, I'll do that. And thanks again for got code.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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