VBA - Adding Footers and Headers

  • Hi,


    This code will update Sheet1's center header by changing A1 cell.


    'Code goes to Sheet1 module
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
    Sheet1.PageSetup.CenterHeader = Sheet1.Range("A1").Value
    End If
    End Sub


    Code line also can be changed like below to format font.


    Sheet1.PageSetup.CenterHeader = "&""Arial,Bold""&9" & Sheet1.Range("A1").Value


    You can also modify this code to set same font format with the source cell by using parameters for fontname, bold and size values.


    I hope this helps.

    Suat

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!