Unique headers/footers from worksheet cell data

RBtrage

New Member
Joined
Dec 18, 2015
Messages
2
I would like a unique header for each worksheet in my workbook based on cell data in the worksheets. I compiled the VBA below, but it cycles through my workbook and updates all headers based on the Active Sheet cell data such that all headers end up the same. For clarification about the VBA below:

  • If I run the macro from Sheet1, Sheet1 cell data is used in all headers.
  • If I run the macro from Sheet2, Sheet2 cell data is used in all headers.
  • If I run the macro from Sheet3, Sheet3 cell data is used in all headers and so on.
<strike></strike>
I would like:

  • Sheet1 cell data to be used in the Sheet1 header
  • Sheet2 cell data to be used in the Sheet2 header
  • Sheet3 cell data to be used in the Sheet3 header, and so on.

Can someone fix the VBA below or suggest alternatives? Thank you!


Sub InsertHeaderFooter()
Dim ws As Worksheet
Application.ScreenUpdating = False

For Each ws In ThisWorkbook.Worksheets

With ws.PageSetup​
.LeftHeader = Range("a1").Text
.CenterHeader = Range("a2").Text
.RightHeader = Range("a3").Text​
End With​

Next ws

Set ws = Nothing
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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