+ Reply to Thread
Results 1 to 9 of 9

Header/Footer How to populate Header with Text and Cell Value together

  1. #1
    Registered User
    Join Date
    12-12-2008
    Location
    sierra foothills
    Posts
    31

    Header/Footer How to populate Header with Text and Cell Value together

    My day to day usage of Excel is very basic therefore any help is greatly appreciated:

    My Access application exports data into a workbook. The data is generated by a query in Access that exports several fields using parameters. Two of the selections are “Fiscal Year” and “Fund Number”.

    All the data is on worksheet “Data” while worksheet “CPAprint” contains the data formatted for printing. I wish to place the text “Fund Number” plus the actual “fund number” from the “Data” worksheet cell containing that information into the left header (Worksheet Header not column header) of the worksheet “CPAprint” as well as the text “Fiscal Year” plus the actual “fiscal year” from the “Data” worksheet into the right header of the worksheet “CPAprint”.

    What is the best practice procedure to accomplish this?

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Header/Footer How to populate Header with Text and Cell Value together

    When you use your macro recorder to set the footer or headers, the code looks something like this.

    Please Login or Register  to view this content.
    You can delete all the irrelevant code and make the header a range value.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Header/Footer How to populate Header with Text and Cell Value together

    Here is an example that puts "Fund Number " and the value of cell A1 from the sheet "Data" as the left header for the sheet "CPAprint":

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Registered User
    Join Date
    12-12-2008
    Location
    sierra foothills
    Posts
    31

    Re: Header/Footer How to populate Header with Text and Cell Value together

    Thanks to both responders...

    Davesexcel: I really need to take some time and understand all your code... Wow

    Arkadi: For someone like me, your solution looks like something I can understand. Where exactly does this code go?

    Sorry for questions that are probably elementary but I'm afraid that's my level of understanding at this point...

    I won't be able to try anything out until tonight (just been called out) but I will get back and check off as solved once I give it a try.

    Thanks so much!

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Header/Footer How to populate Header with Text and Cell Value together

    Lomarica,

    I assume you have existing code already? If you can post that I can integrate it for you.... Ideally provide the cells you want to use as the source for fund number and fiscal year.

  6. #6
    Registered User
    Join Date
    12-12-2008
    Location
    sierra foothills
    Posts
    31

    Re: Header/Footer How to populate Header with Text and Cell Value together

    Arkadi,

    Very kind of you to offer but now that I've had a moment to give your advice a go, I came up with the following and placed it in the ThisWorkbook Object and it works perfectly:


    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Worksheets("CPAprint").PageSetup.LeftHeader = "Fund Number " & Worksheets("Data").Range("H2").Value
    End Sub

    This now brings up another question - how do I format the result so it matches the Center Header which is static text? I assume more code in the same sub routine?

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Header/Footer How to populate Header with Text and Cell Value together

    Like I originally said, use your macro recorder to see what the code looks like.

    Look at my site here.
    http://www.xlorate.com/create-excel-macros.html

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Header/Footer How to populate Header with Text and Cell Value together

    lomarica when you say matches center header, do you mean font and font size?

    You will have to adjust the font name and the size, but this example sets the font to Arial font, 12pt:

    Please Login or Register  to view this content.
    I do think davesexcel makes a good point that you can learn a lot using the macro recorder, though it does generate a lot of extra, useless code that needs some cleaning up.

  9. #9
    Registered User
    Join Date
    12-12-2008
    Location
    sierra foothills
    Posts
    31

    Re: Header/Footer How to populate Header with Text and Cell Value together

    Arkadi,

    Thank you once again for the outstanding help.

    I agree with both you and davesexcel regarding the use of the macro recorder... Having never used it in the past, I looked at davesexcel site and was simply blown away by all the information provided there - very generous. I tried it out late last night and really need to give it a fair chance when both eyes are open.

    At this point I simply wanted to solve my issue with the header and struggle forward with my Access project and for that opportunity, I thank you both. I will most certainly delve into the Excel ether when I have some down time - I'm always up for learning.

    I will post this issue as solved. Cheers!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. size header text footer
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-11-2016, 01:04 PM
  2. VBA Excel Header Footer: It isnt shown full text
    By whoracle in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-19-2012, 04:10 AM
  3. vba code to search text in a word document header and footer
    By Excel-o-ratoR in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-12-2012, 03:16 AM
  4. vba code to seacr text in header and footer of a word document.
    By nitin.srivastava in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2012, 12:07 AM
  5. Copy header & footer with pictures & text
    By Samantha McNeill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-12-2011, 08:32 PM
  6. Changing the color of header and footer text
    By Singhu in forum Excel General
    Replies: 2
    Last Post: 12-15-2005, 06:25 PM
  7. [SOLVED] Header/Footer horizontal margins/text positioning
    By akhergert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2005, 05:30 PM

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