UserForm with MultiPage (tabs). Code to go to next tab on MultiPage

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
Is it possible to have VBA code that will take you to the next tab in a MultiPage? If so would the button be in the MultiPage on each tab? I know you can click on each tab to change. But my users are complaining they dont know which tab they are on. So I was thinking of putting a Next button for them to click once they complete entering data on the current tab they are on.

MultiPage1
Supplier Information
Cost Source
Material
Quantity Breaks

Thanks for the help
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi,
Place following codes in your userforms code page & see if does what you want

VBA Code:
Private Sub NavigateMultiPage(ByVal Direction As XlSearchDirection)

    With Me.MultiPage1
        .Value = IIf(Direction = xlPrevious, .Value - 1, .Value + 1)
        Me.cmdPrevious.Enabled = .Value > 0
        Me.cmdNext.Enabled = .Value < .Pages.Count - 1
    End With
  
End Sub

Private Sub cmdPrevious_Click()
    NavigateMultiPage xlPrevious
End Sub

Private Sub cmdNext_Click()
    NavigateMultiPage xlNext
End Sub

Rather than having buttons on each page, Maybe just placing buttons outside the Multipage will suffice?

1642081745156.png


You will need to rename controls as required

Dave
 
Upvote 0
VBA Code:
'Tabs start at 0.
Private Sub CommandButton1_Click()
  MultiPage1.Value = 1  'To go to 1
End Sub

Private Sub CommandButton2_Click()
  MultiPage1.Value = 2  'To go to 2
End Sub
 
Upvote 0
Hi,
Place following codes in your userforms code page & see if does what you want

VBA Code:
Private Sub NavigateMultiPage(ByVal Direction As XlSearchDirection)

    With Me.MultiPage1
        .Value = IIf(Direction = xlPrevious, .Value - 1, .Value + 1)
        Me.cmdPrevious.Enabled = .Value > 0
        Me.cmdNext.Enabled = .Value < .Pages.Count - 1
    End With
 
End Sub

Private Sub cmdPrevious_Click()
    NavigateMultiPage xlPrevious
End Sub

Private Sub cmdNext_Click()
    NavigateMultiPage xlNext
End Sub

Rather than having buttons on each page, Maybe just placing buttons outside the Multipage will suffice?

View attachment 55144

You will need to rename controls as required

Dave
Nice use of the XlSearchDirection builtin Enum !

May I suggest this little modification to avoid going out of range if the first or last pages are the active ones when first loading the userform

VBA Code:
Private Sub NavigateMultiPage(ByVal Direction As XlSearchDirection)

    With Me.MultiPage1
        .Value = Switch(Len(.Tag) = 0, .Value, Direction = xlPrevious, .Value - 1, Direction = xlNext, .Value + 1)
        .Tag = "Tagged"
        Me.cmdPrevious.Enabled = .Value > 0
        Me.cmdNext.Enabled = .Value < .Pages.Count - 1
    End With
    
End Sub

Private Sub UserForm_Initialize()
    NavigateMultiPage Direction:=Me.MultiPage1.Value
End Sub

Private Sub cmdPrevious_Click()
    NavigateMultiPage xlPrevious
End Sub

Private Sub cmdNext_Click()
    NavigateMultiPage xlNext
End Sub
 
Upvote 0
Solution
Hi,
no worries and improvements to suggestions always welcome - I constantly "raid" built-in enumeration where suitable.
Solution something I adapted from project I worked on with another here for Tab Order in Range & seemed like may work for OPs requirement.


Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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