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:
I would like:
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
Next ws
Set ws = Nothing
Application.ScreenUpdating = True
End Sub
- 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.
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
.CenterHeader = Range("a2").Text
.RightHeader = Range("a3").Text
End With
Next ws
Set ws = Nothing
Application.ScreenUpdating = True
End Sub