Userform multipage

pwwato

New Member
Joined
Jun 10, 2017
Messages
40
Hi all thanks for taking the time to look at this and any advice given.

I have a userform with 2 multipages (2&3) depending on criteria pages are dynamically added to these along with page names.
What I am trying to do is check to see if pages have been added and if they have then remove these pages leaving only the original page page1 .
this is to reset the multipages when criteria changed.

This is the code I am trying to get working.

Dim PGNAME As String
Dim I As Integer
Dim pgno As String
pgno = MultiPage2.Pages.Count
If pgno >= 0 Then

For I = 0 To MultiPage2.Count + 1
PGNAME = MultiPage2.Pages(I).Name This is where I get a runtime error 5 invalid procedure
If PGNAME = ("PAGE1") Then
GoTo 1
Else
MultiPage2.Pages.Remove (PGNAME)
End If
1:
Next I


For I = 0 To MultiPage3.Count + 1
PGNAME = MultiPage3.Pages(I).Name
If PGNAME = ("PAGE1") Then
GoTo 2
Else
MultiPage3.Pages.Remove (PGNAME)
End If
2:
Next I
Else
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi,
looking at your code I guess that you may need to step through pages in reverse.

Not tested but see if following helps

Code:
      Dim PageName As Variant    
      Dim PGNAME As String
       Dim I As Integer, pgno As Integer
    
    For Each PageName In Array(Me.MultiPage2, Me.MultiPage3)
        With PageName
            pgno = .Pages.Count - 1
            If pgno > 0 Then
            For I = pgno To 0 Step -1
                If UCase(.Pages.Item(I).Name) <> "PAGE1" Then .Pages.Remove (I)
            Next I
            End If
        End With
    Next PageName



Following remarks taken from VBA helpfile:

Remarks: This method deletes any control that was added at run time. However, attempting to delete a control that was added at design time will result in an error.

Hope Helpful but
Adjust code as required.

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,120
Members
453,021
Latest member
Justyna P

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