Does anyone know the code to put a number in the right header and.

G

Guest

have it change everytime you print. I got a great answer last time in the
cell format, but now I need to put it in the header part.

This is what I am using to do the regular printing:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
ActiveSheet.Range("K1").Value = ActiveSheet.Range("K1").Value + 1
End If
End Sub

I am still learning and would like to know how to change it to the right
header.
Thanks,
Jennifer
 
G

Guest

try:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
ActiveSheet.PageSetup.RightHeader = ActiveSheet.Range("K1").Value + 1
End If
End Sub
 
G

Gord Dibben

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name <> "Sheet1" Then GoTo whoops
With ActiveSheet
.Range("K1").Value = .Range("K1").Value + 1
.PageSetup.RightHeader = Range("K1").Value
End With
Exit Sub
whoops:
MsgBox "wrong sheet, switch to sheet1"
Cancel = True
End Sub


Gord Dibben MS Excel MVP
 
D

Dave Peterson

I'm not sure if it's important, but you can print a sheet when it's not active.

When I want to do this, I'll create a dedicated macro that prints the sheet and
plop a button on that sheet so the user has to print using that button. (And
disable any other printing.)
 
G

Guest

This code should only be for the header and has nothing to do with the cells
of the normal worksheet. How would the code change? Thanks a million
 

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