Forum Discussion

pda3476's avatar
pda3476
Copper Contributor
Jul 22, 2019

Add the data from a cell into the header

I would like to use the content of cell A1, for example, as the recurring data in the worksheet's header.  Can #Excel do this?

2 Replies

  • pda3476 

     

    Hi,

    You cannot reference a cell in the Header section (Say by typing =C5) that will not grab the value. However there is a tricky way to resolve this issue by recording a simple Macro and trigger it before printing.

    Here is a Tutorial that covers exactly that issue:

    https://www.youtube.com/watch?time_continue=117&v=SMdV7Pz6kg0

     

    if you do not want to watch the Tutorial then do the following:

    1. Hit ALT + F11 >> opens the visual Basic editor
    2. Right Clisk where it says "This Workbook"
    3. Above the white working area there are 2 drop lists
    4. Select "Workbook" from the Left Drop List
    5. Delete the 2 lines that appeared automatically
    6. Copy & Paste this code:

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim Sh As Worksheet
    For Each Sh In Me.Worksheets
    Sh.PageSetup.CenterHeader = Sh.Range("C5").Value
    Next Sh
    End Sub

     

    You can replace CenterHeader by LeftHeader or RightHeader

    replace C5 by any cell of your choice

     

     

    On the Other hand , in the Page Setup dialog box (Shortcut is ALT, P, S, P) >> Header Tab >> Custom Header >> You have some icons to include predefined functionality such as Date, Time, File Name, Sheet Nam ...etc

     

    Hope that helps you

    If you like my answer please mark it as an accepted one.

    Nabil Mourad

    • pda3476's avatar
      pda3476
      Copper Contributor

      nabilmourad

       

      Thank you for the information on the macro option.  I look forward to reviewing and using this option.

Resources