Not really tested, but something like this. You should add error handling
e.g. maybe there is no data after the last HPagebreak
Also, deal with situations where VPageBreaks may be included.
Private Sub CommandButton1_Click()
Dim TopCell As Range
Dim PageCount As Long
With ActiveSheet
Set TopCell = .Range("A2")
For PageCount = 1 To .HPageBreaks.Count
'Assumes values in column A; otherwise adjust column offset value
.PageSetup.RightHeader = TopCell.Value & " - " &
..HPageBreaks(PageCount).Location.Offset(-1, 0).Value
Debug.Print .PageSetup.RightHeader
Set TopCell = .HPageBreaks(PageCount).Location
.PrintOut PageCount, PageCount
Next
'Get the last page data
.PageSetup.RightHeader = TopCell.Value & " - " &
Range("A2").End(xlDown).Value
Debug.Print .PageSetup.RightHeader
.PrintOut PageCount + 1, PageCount + 1
End With
End Sub
NickHK
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a sheet named Inventory that is 60+ print pages long. I have
> row A1 being repeated on every page. Starting with column A2 down I
> have my product codes. What I need is a right header that will consist
> of the first and last product code on every page with a - in between.
> Can someone make me a macros that will do this.
>
|