Select multiple specific pages on Userform Multipage

CheekyDevil2386

New Member
Joined
Oct 19, 2020
Messages
6
Office Version
  1. 2013
Platform
  1. Windows
Hi there!

Is there a simple way to run the below code on multiple, specific pages within a userform multipage?

I want this code to run on pages 1 and 2, but not any others (I have controls on other pages I can't have cleared, so using "userform1.multipage1.controls" isn't an option for me)

VBA Code:
Dim oneControl As Object
For Each oneControl In MultiPage1.Pages(2).Controls
 Select Case TypeName(oneControl)
 Case "TextBox"
 oneControl.Text = vbNullString
 Case "CheckBox"
 oneControl.Value = False
 End Select
Next oneControl

Ideally, i would like to have something like:

VBA Code:
For Each oneControl In MultiPage1.Pages(1+2).Controls

or similar?

Thank you for any assistance anyone can provide :)
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try the following code...

VBA Code:
    Dim pageNumbers As Variant
    Dim pageNumber As Variant
    Dim oneControl As Object
    
    pageNumbers = Array(1, 2)
    
    For Each pageNumber In pageNumbers
        For Each oneControl In MultiPage1.Pages(pageNumber).Controls
            Select Case TypeName(oneControl)
                Case "TextBox"
                    oneControl.Text = vbNullString
                Case "CheckBox"
                    oneControl.Value = False
            End Select
        Next oneControl
    Next pageNumber

Hope this helps!
 
Upvote 0
Solution
You could create a function that takes a page as an argument.
VBA Code:
Function ClearPage(pg As MsForms.Page)
Dim ctl As MsForms.Control

    For Each ctl In pg.Controls
        Select Case TypeName(ctl)
            Case "TextBox"
                ctl.Text = vbNullString
                ClearPage = ClearPage + 1
            Case "CheckBox"
                ctl.Value = False
                ClearPage = ClearPage + 1
        End Select
    Next ctl

End Function
That could then be called like this.
VBA Code:
    ClearPage Me.MultiPage1.Pages(0)
    ClearPage Me.MultiPage1.Pages(1)
 
Upvote 0
Thank you both very much for the answers above! Much appreciated and utmost apologies for the delay in my reply.

Haven't yet managed to get it into the project yet but looking at the two they'll be perfect for a few other ideas I have too :)

Really appreciate the help guys, thank you for the time you gave :)
 
Upvote 0

Forum statistics

Threads
1,214,897
Messages
6,122,148
Members
449,066
Latest member
Andyg666

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