Change around these Index/page number codes

klarowe

Active Member
Joined
Mar 28, 2011
Messages
389
Currently I have these 2 codes on this report:
Code:
Sub SequentiallyNumberVisiblePagesOnly()
    Dim lx As Long
    Dim lVisibleSheets As Long
    For lx = 1 To Worksheets.Count
        If Worksheets(lx).Visible = True Then lVisibleCount = lVisibleCount + 1
        With Worksheets(lx).PageSetup
            .RightFooter = lVisibleCount
        End With
    Next
End Sub
Sub IndexNumber()
    Dim lx As Long
    Dim sIndex As String
    Dim sIndexStartRange As String
    Dim lVisibleCount As Long
    sIndex = "Index"
    sIndexStartRange = "A7"
    Worksheets(sIndex).Range("A7:A100").Cells.ClearContents
    With Worksheets(sIndex).Range("A7")
        For lx = 1 To Worksheets.Count
            Select Case Worksheets(lx).Name
            Case Else
                If Worksheets(lx).Visible = True Then
                    lVisibleCount = lVisibleCount + 1
                End If
                If Worksheets(lx).Visible = True Then .Offset(lx - 1, 0) = lVisibleCount
            End Select
        Next
    End With
End Sub

And they work great for the most part. The problem I am having is that right now if a single sheet goes onto extra pages within the sheet, all pages within the sheet keep the same page number. SO when it prints out the entire report the page number in the bottom shows up something along the lines of "Page 1" then "Page 2", "Page 2", "Page 2", "Page 3". Which apparently can get confusing to the customer.

So I need to modify the above codes to add in those pages towards the page count and then also change the numbering in the index to match.

Now it doesn't matter if it just shows the start page or if it shows the range of pages (ie 1 - Pinion; 2-4 - Impeller; 5 - Laby Sleeve OR 1 - Pinion; 2 - Impeller; 5 - Laby Sleeve).

I know this is a tough one and sorry for the long post but I may not be on for a few days and wanted to give you guys all the info I could for now.

Thanks in advance.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Look at this code as it page numbers and copy numbers, see if it helps

Sub PrintCopies1()

Dim CopiesCount As Long
Dim CopieNumber As Long
CopiesCount = Application.InputBox("How many copies do you want", Type:=1)

For CopieNumber = 1 To CopiesCount
With ActiveSheet
' This example print the number in cell A1
.Range("M1").Value = CopieNumber & " of " & CopiesCount

'If you want the number in the footer use this line
'.PageSetup.LeftFooter = CopieNumber & " of " & CopiesCount

'Print the sheet
.PrintOut
End With
Next CopieNumber
End Sub
 
Upvote 0
Sorry for the delay, but I'm not really sure how I would integrate any part of that in to the original code to do what I need it to....
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

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