How do I make a UserForm page visible in an If statement.

thardin

Board Regular
Joined
Sep 29, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
I have a MultiPage Userform with a total of 10 pages. I currently have 2 pages where the visibility is set to False.

I'd like to create an If statement where if It's Monday, pages 1 and 2 are visible, Else visible = False.

How would I do this?
Thanks
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi,
try following & see if does what you want

VBA Code:
Private Sub UserForm_Initialize()
    Dim i As Long
    For i = 0 To 1
        Me.MultiPage1.Pages(i).Visible = Weekday(Date, vbSunday) = vbMonday
    Next
End Sub

I have assumed Page1 is the first page in the multipage whose index is 0.
Change name of MultiPage1 if required

Dave
 
Upvote 0
Solution
Hi,
try following & see if does what you want

VBA Code:
Private Sub UserForm_Initialize()
    Dim i As Long
    For i = 0 To 1
        Me.MultiPage1.Pages(i).Visible = Weekday(Date, vbSunday) = vbMonday
    Next
End Sub

I have assumed Page1 is the first page in the multipage whose index is 0.
Change name of MultiPage1 if required

Dave
I get an "invalid use of Me" compile error
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,337
Members
448,568
Latest member
Honeymonster123

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