Select multiple specific pages on Userform Multipage

CheekyDevil2386

New Member
Joined
Oct 19, 2020
Messages
4
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

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).

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,727
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!
 
Solution

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
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)
 

CheekyDevil2386

New Member
Joined
Oct 19, 2020
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
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 :)
 

Forum statistics

Threads
1,141,863
Messages
5,709,053
Members
421,611
Latest member
Lisa W

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
Top