Multi Page hide issue

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
Hi

I have a userform (Userform1) on it i have a multipage with tabs. When the userform opens all tabs except 1 is visible

VBA Code:
Private Sub UserForm_Initialize()
Me.MultiPage1.Pages(0).Visible = True
Me.MultiPage1.Pages(1).Visible = False
Me.MultiPage1.Pages(2).Visible = False
Me.MultiPage1.Pages(3).Visible = False
End Sub

I have command buttons on the userform, so if command button 2 is clicked then the second tab, which is Pages.(1) will show and the others including the first will be set to false

VBA Code:
Private Sub CommandButton2_Click()
Me.MultiPage1.Pages(0).Visible = False
Me.MultiPage1.Pages(1).Visible = True
Me.MultiPage1.Pages(2).Visible = False
Me.MultiPage1.Pages(3).Visible = False
End Sub

My problem is that all the textboxes and buttons etc. on the pages DO NOT show until i click the tab, Is there another way I can do this
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try this

VBA Code:
Private Sub UserForm_Initialize()
  Me.MultiPage1.Pages(0).Visible = True
  Me.MultiPage1.Pages(1).Visible = False
  Me.MultiPage1.Pages(2).Visible = False
  Me.MultiPage1.Pages(3).Visible = False
End Sub

Private Sub CommandButton1_Click()
  Me.MultiPage1.Pages(0).Visible = True
  Me.MultiPage1.Pages(1).Visible = False
  Me.MultiPage1.Pages(2).Visible = False
  Me.MultiPage1.Pages(3).Visible = False
  MultiPage1.Value = 0
End Sub

Private Sub CommandButton2_Click()
  Me.MultiPage1.Pages(0).Visible = False
  Me.MultiPage1.Pages(1).Visible = True
  Me.MultiPage1.Pages(2).Visible = False
  Me.MultiPage1.Pages(3).Visible = False
  MultiPage1.Value = 1
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0
You can compact the code as follows

VBA Code:
Private Sub UserForm_Initialize()
  Call VisiblePage(0)
End Sub

Private Sub CommandButton1_Click()
  Call VisiblePage(0)
End Sub
Private Sub CommandButton2_Click()
  Call VisiblePage(1)
End Sub
Private Sub CommandButton3_Click()
  Call VisiblePage(2)
End Sub

Sub VisiblePage(n As Integer)
  With MultiPage1
    .Pages(0).Visible = False
    .Pages(1).Visible = False
    .Pages(2).Visible = False
    .Pages(3).Visible = False
    .Pages(n).Visible = True
    .Value = n
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

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