ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop through pages in multipage control (https://www.excelbanter.com/excel-programming/388611-loop-through-pages-multipage-control.html)

ExcelMonkey

Loop through pages in multipage control
 
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



merjet

Loop through pages in multipage control
 
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



ExcelMonkey

Loop through pages in multipage control
 
Yup that did it. Thanks - could not for the life of think outside of the
code I had already written. Thanks again.

EM

"merjet" wrote:

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





All times are GMT +1. The time now is 05:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com