Ok so what I want to is to place in the right hand footer a page number for an excel report.
To do this I am using a VBA macro to generate the pages and the information is copied from the Header details sheet to a copy of the template sheet which then is used an actual page for the report.
The problem is that the intro page prints with the initial value as expected but when going to the next page it randomly increments by 8 so it becomes "page 9 of x". How can I stop it from doing this random jump?
Report Pages
Sub ReportPages()
Dim areas As Integer
Dim pageNumberTotal As Integer
areas = 1
' Unhides the Template sheet so it is ready to be used.
Worksheets("Template").Visible = True
' Add new pages based on the header details sheet.
Sheets("Header Details").Select
' Select cell A14 as the basis to fill out the template with data.
Range("A14").Select
Do While IsEmpty(ActiveCell) = False
    ActiveCell.Offset(1, 0).Select
    areas = areas + 1
Loop
pageNumberTotal = areas + 5
' Matches the amount of areas tested that have been specified in the Header Details sheet
Do While areas > 1
    For i = 1 To Worksheets.Count
        If Worksheets(i).Name = areas - 1 Then
        exists = True
        End If
    Next i
    If exists = True Then
        areas = areas - 1
        exists = False
    Else
        ' Decrement by 1 and copy the relevant data to the template.
        areas = areas - 1
        Sheets("Template").Select
        Sheets("Template").Copy After:=Worksheets("Template")
        Sheets("Template (2)").Select
        Sheets("Template (2)").Name = areas
        Range("I6").Select
        ActiveCell = areas
        ' Call the WetDry function and then protect the sheet.
        Call WetDry
    End If
Loop
' Closes the template sheet when it is done.
Worksheets("Template").Visible = False
'If ActiveSheet.Name = 1 Then
    'Dim pageNumberSetting As String
    'Dim pageNumber As Integer
    'pageNumber = 1
    'Sheets("Front Page").Select
    ' Sets the font type and size of the page number and page total in the bottom right hand corner of the page.
    'pageNumberSetting = "&B&9Page " & pageNumber & " of " & pageNumberTotal & "    &K00+000." & Chr(10) & "" & Chr(10) & "" & Chr(10) & ""
    'With ActiveSheet.PageSetup
        '.RightFooter = pageNumberSetting
    'End With
    'pageNumber = pageNumber + 1
    'ActiveSheet.Next.Activate 
'End If
    ' Calls the next function and passes the value of the page number setting.
    Call FrontBackPages       
 End Sub
Front and Back Pages
Sub FrontBackPages()
' Sets the preliminary features for the start of the report.
' Declarations of variables.
If ActiveSheet.Name = 1 Then
    Dim pageNumberSetting As String
    Dim pageNumber As Integer
    pageNumber = 1
    Sheets("Front Page").Select
    ' Debug message - please ignore.
    ' MsgBox " The Name of the active sheet is " & ActiveSheet.Name
    ' Sets the font type and size of the page number and page total in the bottom right hand corner of the page.
    pageNumberSetting = "&B&9Page " & pageNumber & " of " & pageNumberTotal & "    &K00+000." & Chr(10) & "" & Chr(10) & "" & Chr(10) & ""
    With ActiveSheet.PageSetup
        .RightFooter = pageNumberSetting
    End With
    pageNumber = pageNumber + 1
    ActiveSheet.Next.Activate
    ' Selects the "Appx Summary" sheet and propegates it with information from other parts of the workbook,
    ' generates a page number for this part of the report.
    Do While ActiveSheet.Name <> "Appx Summary"
        pageNumberParameter = "&B&9Page " & pageNumber & " of " & pageNumberTotal & "    &K00+000."
        ' If the active sheet condition is met then the "Slip Resistance Testing" sheet is selected and is
        ' given a page number that will be placed in the lower right hand corner of the page.
        If ActiveSheet.Name = "Slip Resistance Testing" Then
            With ActiveSheet.PageSetup
                .FirstPage.RightFooter.Text = pageNumberParameter
            End With
            pageNumber = pageNumber + 1
            pageNumberParameter = "&B&9Page " & pageNumber & " of " & pageNumberTotal & "    &K00+000."
        End If
        ' The "Template" sheet is selected and the page number is decremented by 1.
        If ActiveSheet.Name = "Template" Then
            pageNumber = pageNumber - 1
        End If
        ' The active sheet is selected and in the right - hand footer is given a page number.
        ' After this the next sheet is activated.
        With ActiveSheet.PageSetup
            .RightFooter = pageNumberParameter
        End With
        pageNumber = pageNumber + 1
        ActiveSheet.Next.Activate
    Loop
    ' The page number is then added to the page and also gives the total page number as well.
    ' This will place the page number in the bottom right hand corner of the page..
        pageNumberParameter = "&B&9Page " & pageNumber & " of " & pageNumberTotal & "    &K00+000."
    With ActiveSheet.PageSetup
        .FirstPage.RightFooter.Text = pageNumberParameter
    End With
End If
' Selectes the "Header Details" sheet and the prompts the user that the pages have been successfully added.
Sheets("Header Details").Select
MsgBox "Pages Added!"
End Sub
 
    