Loop through pages in multipage control

G

Guest

I have a line of code which hides pages in a multipage control:

If pg.Index <> SomeVariable Then
pg.Visible = False
End If

I now want to replace SomeVariable with an ArrayOfVariables. There will be
two variables in the array - say 1 and 2. However the code below does not
work as the page which survives the first loop gets axed during the second
loop. What do I need to do to preserve the page that is retained in earlier
iterations of the loop. I almost need to pass all true tests in another
array.

Private Function PageRetain()
Dim X As Integer
For X = 0 To UBound(ListItemArray) ' this equals 1
For Each pg In UserForm1.MultiPage1.Pages
If pg.Index <> ListItemArray(X) - 1 Then ' this array has 2 elements:
1, 2
pg.Visible = False
End If
Next
Next
End Function
 
M

merjet

It seems like you should make the inner loop the outer one (and vice-
versa) and set pg.Visible = False before the inner loop and change it
to True if pg.Index = ListItemArray(X) - 1

Hth,
Merjet
 
G

Guest

Yup that did it. Thanks - could not for the life of think outside of the
code I had already written. Thanks again.

EM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top