+ Reply to Thread
Results 1 to 14 of 14

VBA Code for Header through cell reference.

  1. #1
    Registered User
    Join Date
    02-14-2020
    Location
    AMsterdam, Netherlands
    MS-Off Ver
    365
    Posts
    78

    VBA Code for Header through cell reference.

    Hello all!

    Im trying generate a pricelist where i want to have data from a cell (from the first sheet), in the header of the first and second sheet.
    (Sheet1 is actually a coversheet to go with the pricelist, i want to be able to see on the pricelist (Sheet2) in the leftheader, who we actually made this pricelist for. (name of customer)

    Im using a dropdown to get the customer name, find it in coversheet a2.)

    This reference of Coversheet A2 needs to be printed in the headers of these two sheets only.
    (In my original file i have several other sheets too, but it unnecessary to have it in there.)


    I have seen some videos, but lack skill to adjust the code of those.
    The ones ive found do print headers from a cell reference, but "a2" from each sheet, not solely from the first one.
    Ive seen the "beforePrint" function, that will do for us.
    The beforeSave function is also a good option, i think.

    Can you guys and girls help me out a bit?

    Thanks a lot in advance!
    Attached Files Attached Files
    Last edited by Mr_Excell_Ensie; 10-05-2022 at 11:10 AM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: VBA Code for Header through cell reference.

    Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your Coversheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in A2.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    02-14-2020
    Location
    AMsterdam, Netherlands
    MS-Off Ver
    365
    Posts
    78

    Re: VBA Code for Header through cell reference.

    This is pretty neat!
    Thanks for your help thus far, i wonder though, if you could make it so that the target becomes; leftheader or centerheader, or even footer maybe?

    My actual rows and columns are full, my wish is to have this really in the header or footer.
    Can you alter it to that please?

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: VBA Code for Header through cell reference.

    Try:
    Please Login or Register  to view this content.
    The headers will be visible in Page Layout view.
    Last edited by Mumps1; 10-05-2022 at 12:32 PM.

  5. #5
    Registered User
    Join Date
    02-14-2020
    Location
    AMsterdam, Netherlands
    MS-Off Ver
    365
    Posts
    78

    Re: VBA Code for Header through cell reference.

    AWESOME!

    Thank you guys very much!

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: VBA Code for Header through cell reference.

    You are very welcome.

  7. #7
    Registered User
    Join Date
    02-14-2020
    Location
    AMsterdam, Netherlands
    MS-Off Ver
    365
    Posts
    78

    Re: VBA Code for Header through cell reference.

    Just out of curiosity, how would it be when id have a wish to use both center and left targets?

    Is there a target2 that needs to be written?

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: VBA Code for Header through cell reference.

    If it's a fixed text, place the desired text between the quotation marks to the right of LeftHeader.

  9. #9
    Registered User
    Join Date
    02-14-2020
    Location
    AMsterdam, Netherlands
    MS-Off Ver
    365
    Posts
    78

    Re: VBA Code for Header through cell reference.

    got that, and when I would want that to be from a dropdown as well?

    One i could really use for a dropdown of validity per month, and the other for which customer the pricelist is created.

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: VBA Code for Header through cell reference.

    Please attach an updated file including the second drop down and explain in detail want you want to do.

  11. #11
    Registered User
    Join Date
    02-14-2020
    Location
    AMsterdam, Netherlands
    MS-Off Ver
    365
    Posts
    78

    Re: VBA Code for Header through cell reference.

    I made some changes, this should help clarify.

    Thanks a lot for your help! i wonder what the code looks like!

    Must be awesome to be you!
    Attached Files Attached Files

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: VBA Code for Header through cell reference.

    Try this macro. You must select a value in A2 first and then select the month in A3.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    02-14-2020
    Location
    AMsterdam, Netherlands
    MS-Off Ver
    365
    Posts
    78

    Re: VBA Code for Header through cell reference.

    This is magic, thank you very much Mumps!

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: VBA Code for Header through cell reference.

    My pleasure.

+ 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. Header to cell reference
    By 4lowie in forum Excel General
    Replies: 3
    Last Post: 05-01-2014, 08:19 AM
  2. Reference Cell in Header
    By GreatLakesJK in forum Excel General
    Replies: 10
    Last Post: 11-29-2010, 08:03 PM
  3. Reference cell from top row of each page in header
    By mzemble in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-06-2009, 12:45 AM
  4. Print header from cell reference
    By Beeblebrox in forum Excel General
    Replies: 4
    Last Post: 04-23-2009, 04:20 PM
  5. [SOLVED] cell reference in header row
    By ML in forum Excel General
    Replies: 4
    Last Post: 08-26-2005, 02:05 PM
  6. Cell Reference in Header
    By Dave in forum Excel General
    Replies: 1
    Last Post: 05-20-2005, 04:06 PM
  7. code to print text from a cell reference in header
    By rabbi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-21-2005, 02:20 AM

Tags for this Thread

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