ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   custom header (https://www.excelbanter.com/excel-discussion-misc-queries/42196-custom-header.html)

Marlis

custom header
 
I would like to know how to set up a custom header which shows the data in a
perticular cell (i.e. - C9 shows the number 100, so I want the header in all
the pages,except the first, to show "100".

Thank you

Dave Peterson

One way is to use a macro.

Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim myHeaderStr As String
Dim iCtr As Long

myHeaderStr = Worksheets("sheet3").Range("C9").Value

For iCtr = 2 To Worksheets.Count
Worksheets(iCtr).PageSetup.LeftHeader = myHeaderStr
Next iCtr

End Sub

(I used c9 on sheet3 (you didn't say which sheet to use).)

This code goes in the ThisWorkbook module.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Marlis wrote:

I would like to know how to set up a custom header which shows the data in a
perticular cell (i.e. - C9 shows the number 100, so I want the header in all
the pages,except the first, to show "100".

Thank you


--

Dave Peterson

Marlis

I don't know what I am doing wrong. I followed the directions for copying
and pasting a macro from the site you recommended....but I can't get it to
work.

My workbook is named "book1", the sheet is named "Order form" and the cell
is "c9".

What do you suggest for getting this to work?

Thank you

"Dave Peterson" wrote:

One way is to use a macro.

Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim myHeaderStr As String
Dim iCtr As Long

myHeaderStr = Worksheets("sheet3").Range("C9").Value

For iCtr = 2 To Worksheets.Count
Worksheets(iCtr).PageSetup.LeftHeader = myHeaderStr
Next iCtr

End Sub

(I used c9 on sheet3 (you didn't say which sheet to use).)

This code goes in the ThisWorkbook module.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Marlis wrote:

I would like to know how to set up a custom header which shows the data in a
perticular cell (i.e. - C9 shows the number 100, so I want the header in all
the pages,except the first, to show "100".

Thank you


--

Dave Peterson


Dave Peterson

Make sure you pasted that workbook_beforeprint routine into the ThisWorkbook
module.

If you've verified that the code is there, what happens when you hit
File|PrintPreview?

And you may want to post the code you used.

Marlis wrote:

I don't know what I am doing wrong. I followed the directions for copying
and pasting a macro from the site you recommended....but I can't get it to
work.

My workbook is named "book1", the sheet is named "Order form" and the cell
is "c9".

What do you suggest for getting this to work?

Thank you

"Dave Peterson" wrote:

One way is to use a macro.

Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim myHeaderStr As String
Dim iCtr As Long

myHeaderStr = Worksheets("sheet3").Range("C9").Value

For iCtr = 2 To Worksheets.Count
Worksheets(iCtr).PageSetup.LeftHeader = myHeaderStr
Next iCtr

End Sub

(I used c9 on sheet3 (you didn't say which sheet to use).)

This code goes in the ThisWorkbook module.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Marlis wrote:

I would like to know how to set up a custom header which shows the data in a
perticular cell (i.e. - C9 shows the number 100, so I want the header in all
the pages,except the first, to show "100".

Thank you


--

Dave Peterson


--

Dave Peterson

Marlis

I am lost as to what to do. I don't seem to understand what to do.

"Dave Peterson" wrote:

One way is to use a macro.

Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim myHeaderStr As String
Dim iCtr As Long

myHeaderStr = Worksheets("sheet3").Range("C9").Value

For iCtr = 2 To Worksheets.Count
Worksheets(iCtr).PageSetup.LeftHeader = myHeaderStr
Next iCtr

End Sub

(I used c9 on sheet3 (you didn't say which sheet to use).)

This code goes in the ThisWorkbook module.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Marlis wrote:

I would like to know how to set up a custom header which shows the data in a
perticular cell (i.e. - C9 shows the number 100, so I want the header in all
the pages,except the first, to show "100".

Thank you


--

Dave Peterson


Dave Peterson

Maybe posting what you tried would help get a better response.

Marlis wrote:

I am lost as to what to do. I don't seem to understand what to do.

"Dave Peterson" wrote:

One way is to use a macro.

Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim myHeaderStr As String
Dim iCtr As Long

myHeaderStr = Worksheets("sheet3").Range("C9").Value

For iCtr = 2 To Worksheets.Count
Worksheets(iCtr).PageSetup.LeftHeader = myHeaderStr
Next iCtr

End Sub

(I used c9 on sheet3 (you didn't say which sheet to use).)

This code goes in the ThisWorkbook module.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Marlis wrote:

I would like to know how to set up a custom header which shows the data in a
perticular cell (i.e. - C9 shows the number 100, so I want the header in all
the pages,except the first, to show "100".

Thank you


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 04:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com