Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Marcro for Footer to Selected Worksheets Hello, Below is VBA script that I have

ID: 3565148 • Letter: M

Question

Marcro for Footer to Selected Worksheets

Hello,

Below is VBA script that I have to add headers & footers to an active worksheets. Is there a way to adjust this to apply to worksheets that I have selected?

Sub Footer_Sheet()
'
' Footer_Sheet Macro

Application.ScreenUpdating = False
  
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = "&""Arial,Regular""&A"
.RightHeader = ""
.LeftFooter = "&""Arial,Regular""&Z&F"
.CenterFooter = ""
.RightFooter = "&""Arial,Regular""&D - &T"
End With
Application.ScreenUpdating = True
  
End Sub

Explanation / Answer

Hi,

Try this

Sub Footer_Sheet()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In ThisWorkbook.Windows(1).SelectedSheets
    With sh.PageSetup
        .LeftHeader = ""
        .CenterHeader = "&""Arial,Regular""&A"
        .RightHeader = ""
        .LeftFooter = "&""Arial,Regular""&Z&F"
        .CenterFooter = ""
        .RightFooter = "&""Arial,Regular""&D - &T"
    End With
Next sh
Application.ScreenUpdating = True
End Sub