VBA headers and footers

Russk68

Well-known Member
Joined
May 1, 2006
Messages
589
Office Version
  1. 365
Platform
  1. MacOS
Hi All
I would like to have 6 cells in a sheet with each one representing a position. I would like the header and footer on every sheet to reference what's in each cell.
Possible?

Thank you!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Is this the sort of thing you mean?
Code:
ActiveSheet.PageSetup.LeftHeader = Range("A1").Text
 
Upvote 0
Hi Peter
I'm not sure where to put that from what I'm thinking.
Example: Sheet 1 would be where I enter text in A1 to show up in left header. All sheets then have A1 text in the left header.

Thank you!
 
Upvote 0
I'm not sure where to put that from what I'm thinking.
Example: Sheet 1 would be where I enter text in A1 to show up in left header. All sheets then have A1 text in the left header.
- All sheets would have the A1 text from cell A1 in Sheet 1?
or
- All sheets would have the text from cell A1 in their own sheet?
 
Upvote 0
Hi Peter
The first choice.
Thanks
Try something like this then.

Code:
Sub AddHeaders()
  Dim ws As Worksheet
  
  For Each ws In Worksheets
    ws.PageSetup.LeftHeader = Sheets("Sheet1").Range("A1").Text
  Next ws
End Sub
 
Upvote 0
Hi Peter

Do I put the code in sheet 1?

I'm going to give it a shot here. Is this how to add the other headers?

Code:
Sub AddHeaders()
  Dim ws As Worksheet
  
  For Each ws In Worksheets
    ws.PageSetup.LeftHeader = Sheets("Sheet1").Range("A1").Text
    ws.PageSetup.RightHeader = Sheets("Sheet1").Range("B1").Text
 Next ws

End Sub
 
Upvote 0
It works!
What a time saver this is.
Thank you Peter!
 
Upvote 0
Do I put the code in sheet 1?
I would put it in a general Module, not a worksheet module, though it shouldn't hurt in a worksheet module (unless you subsequently delete that worksheet).
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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