+ Reply to Thread
Results 1 to 6 of 6

If Statement Within Header/Footer Population Macro

  1. #1
    Registered User
    Join Date
    03-05-2014
    Location
    Colorado
    MS-Off Ver
    Excel 2007
    Posts
    7

    If Statement Within Header/Footer Population Macro

    Hi,

    If anyone is willing to take time to help, I could use some guidance on inserting an "if sheet name equals" statement within a macro I have for auto-populating header/footer of a worksheet. I'm still a beginner in learning macros, but feel this should be something simple I can figure out. Unfortunately I can't seem to get my head wrapped around a fix.

    The maco loops through each worksheet and populates the header and footer based on a cell reference. However, one worksheet needs to have information populated in the left footer. I tried to do this by referencing the sheet name, but I get an object error.

    It works if I use ActiveSheet.Name = "SheetName". The only issue is if I use a print workbook function, the left footer does not update. I have to actively select the referenced worksheet and print preview to get it to update.

    How can I have this macro work without using ActiveSheet.Name so I don't have to actively select the sheet, and manually perform a print preview?

    The code I'm using is (red text is where I need the help):
    Please Login or Register  to view this content.
    I would greatly appreciate the time anyone is willing to offer.
    Last edited by idelta; 03-24-2014 at 08:13 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Have you tried using ws instead of ActiveSheet?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-05-2014
    Location
    Colorado
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: If Statement Within Header/Footer Population Macro

    I have. I receive an error stating - "Object variable or With block variable not set"

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: If Statement Within Header/Footer Population Macro

    Quote Originally Posted by idelta View Post
    I would greatly appreciate the time anyone is willing to offer.
    Does this work?

    Please Login or Register  to view this content.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  5. #5
    Registered User
    Join Date
    03-05-2014
    Location
    Colorado
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: If Statement Within Header/Footer Population Macro

    mc84excel,

    Wow... yes, it works! I am ecstatic as I had been beating my head over this for a few hours. The resolution (in no way downgrading your solution) is just so simple.

    Thank you!!

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: If Statement Within Header/Footer Population Macro

    Quote Originally Posted by idelta View Post
    mc84excel,

    Wow... yes, it works! I am ecstatic as I had been beating my head over this for a few hours. The resolution (in no way downgrading your solution) is just so simple.

    Thank you!!
    No problem. We all get those moments from time to time.

+ 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. Macro to Add Header & Footer
    By dingdang in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2012, 10:04 PM
  2. Setting Header / Footer in a macro
    By RevJeff in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2011, 11:45 AM
  3. Replies: 4
    Last Post: 08-17-2011, 01:04 AM
  4. Macro changes Header/Footer to all worksheets
    By RonNCmale in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-19-2010, 09:54 PM
  5. Header and Footer Macro
    By dhuang via OfficeKB.com in forum Excel General
    Replies: 1
    Last Post: 10-31-2005, 01:05 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