I have a multipage which I have successfully filled with code based on excel table.
Where there are more than one page to display, the last page always ends up being the first in the order of tabs, even though its index is something other than 0.
For instance:
4 pages - Index 0, 1, 2, 3
Displays pages in multipage in the order of 3, 0, 1, 2
i.e. the last page always shows up on the first tab, even though its index is not 0
It is like the code stops and displays the multipage without the final update (makes me think it is something to do with the AfterUpdate, which I haven't put any code into)
Code is below:
Code
Dim numPages As Integer
Private Sub Industry_Change()
Dim i, j, k As Long, LastRow As Long
Dim size, index, count As Integer
Dim MyPage As Object
Dim paid As Double
'Count number of rows in Table
LastRow = Sheets("Table").Range("A" & Rows.count).End(xlUp).Row
count = 0
index = 0
'Remove excess pages on multipage control
If numPages > 1 Then
For j = 1 To numPages - 1
MultiPage1.Pages.Remove (1)
Next
numPages = 1
End If
'For each row of data in the Table | index value starts at 0
For i = 2 To LastRow
If Sheets("Table").Cells(i, "B").Value = (Industry) Or _
Sheets("Table").Cells(i, "B") = Val(Industry) Then
count = count + 1
If count > 1 Then
MultiPage1.Pages.Add
index = count - 1
numPages = count
MultiPage1.Pages(0).Controls.Copy
MultiPage1.Value = index
MultiPage1.Pages(MultiPage1.Value).Paste
End If
MultiPage1.Value = index
MultiPage1.Pages(MultiPage1.Value).Caption = "Project " & count
'MultiPage1.Pages(MultiPage1.Value).Caption = Cells(i, "H").Value
'Enter information into text boxes for each project
txtTitle.Value = Cells(i, "H").Value
txtEIS.Value = Cells(i, "A").Value
txtComponent.Value = Cells(i, "D").Value
txtPrinciple.Value = Cells(i, "E").Value
txtTimeFrame.Value = Cells(i, "F").Value
txtStartDate.Value = Cells(i, "K").Value
txtEndDate.Value = Cells(i, "L").Value
txtAmendedDate.Value = Cells(i, "M").Value
txtFunding.Value = Cells(i, "O").Value
txtFunding = Format(txtFunding, "#,##0")
txtPaid.Value = Cells(i, "P").Value
txtPaid = Format(txtPaid, "#,##0")
txtProcurement.Value = Cells(i, "G").Value
txtOrganisation.Value = Cells(i, "I").Value
txtProvider.Value = Cells(i, "J").Value
txtReporting.Value = Cells(i, "Q").Value
txtReportingStatus.Value = Cells(i, "R").Value
txtKPI1.Value = Cells(i, "S").Value
txtStatus1.Value = Cells(i, "T").Value
txtProgress1.Value = Cells(i, "U").Value
txtKPI2.Value = Cells(i, "V").Value
txtStatus2.Value = Cells(i, "W").Value
txtProgress2.Value = Cells(i, "X").Value
txtKPI3.Value = Cells(i, "Y").Value
txtStatus3.Value = Cells(i, "Z").Value
txtProgress3.Value = Cells(i, "AA").Value
txtKPI4.Value = Cells(i, "AB").Value
txtStatus4.Value = Cells(i, "AC").Value
txtProgress4.Value = Cells(i, "AD").Value
txtKPI5.Value = Cells(i, "AE").Value
txtStatus5.Value = Cells(i, "AF").Value
txtProgress5.Value = Cells(i, "AG").Value
txtFundsTotal.Value = Cells(i, "C").Value
'Move index(0) to last page
'If numPages > 1 Then
'MultiPage1.Page1.Move
'End If
'Accumulate the amount paid for userform total paid
paid = paid + Cells(i, "P").Value
TextBox1.Value = MultiPage1.Value
End If
Next
txtPaidTotal.Value = paid
txtPaidTotal = Format(txtPaidTotal, "#,##0")
txtFundsTotal = Format(txtFundsTotal, "#,##0")
'MultiPage1.page1.index = 0
MultiPage1.Value = 0
End Sub
Private Sub UserForm_Activate()
numPages = 1
End Sub
Display More