+ Reply to Thread
Results 1 to 3 of 3

how to include a variable in the header and/or footer of a worksheet

  1. #1
    Registered User
    Join Date
    11-24-2004
    Posts
    19

    how to include a variable in the header and/or footer of a worksheet

    Hi, I am building a template to be used by multiple teams. I would like them to enter their team name once in the first worksheet of a multi sheet workbook. I would like to have the team name appear in the header and footer of each worksheet also without having to modify the header or footer manually. Is there a way to do this?

  2. #2
    Forum Contributor
    Join Date
    01-06-2004
    Location
    Carbondale CO
    Posts
    245
    Hi,
    In the example below the Team puts there name in a cell that is a named range called TeamName.
    INSERT > NAME >DEFINE
    This named range is on a worksheet named Entry Sheet.
    Change both of these to suit.

    Place this code in the ThisWorkbook module.
    Right click a worksheet tab choose view code.
    Double click ThisWorkbook

    Option Explicit

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Call AddNameToHeadFoot
    End Sub
    Private Sub AddNameToHeadFoot()
    Dim str As String
    str = Sheets("Entry Sheet").Range("TeamName").Value 'Modify sheet name and named range to suit
    ActiveSheet.PageSetup.RightFooter = "&""""&10" & str '<==== 10 is font size
    ActiveSheet.PageSetup.RightHeader = "&""""&10" & str '<==== 10 is font size
    End Sub

    You can use these variables to place the team names in different areas of the headers and footers
    .LeftHeader
    .CenterHeader
    .RightHeader
    .LeftFooter
    .CenterFooter
    .RightFooter


    HTH
    Last edited by Casey; 04-14-2006 at 03:06 PM.
    Casey

  3. #3
    Ron2005
    Guest

    Re: how to include a variable in the header and/or footer of a worksheet

    if by header you simply mean the top of the other tabs then in the sell
    you want it to appear on enter:

    ='sheetnameoffirstworksheet!(A10) change A10 to the cell
    number where it is on the first worksheet.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1