How to change the number in a header with each print?

G

Guest

This is in the right header only, no cells in the regular worksheet.
I am doing this for a document where each time I print the number in the
right header has to change without anyone seeing it from the regular
worksheet. I would really appreciate the help as I am still learning excel.
 
J

Jennifer

This is in the right header only, no cells in the regular worksheet.
I am doing this for a document where each time I print the number in the
right header has to change without anyone seeing it from the regular
worksheet. I would really appreciate the help as I am still learning excel.


You could use a macro to do this. I'd save your number in a specific
cell in a hidden column. In the example below, I'm saving a number in
the cell A1 on Sheet 1 just as an example. The macro adds 1 to the
number and then uses that number to modify what is in the Right Hand
Header.

Sub ModifyHeader()
With ActiveSheet.PageSetup
Sheet1.Cells(1, 1).Value = Sheet1.Cells(1, 1).Value + 1
.RightHeader = Sheet1.Cells(1, 1).Value
End With
End Sub

Then you can use the BeforePrint event to call the macro. This can be
found by going to Tools..Macro..Visual Basic Editor. Use the
ThisWorkbook object.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Call ModifyHeader
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top