+ Reply to Thread
Results 1 to 12 of 12

VBA Apply Formatting To Sheets With Specific Name

  1. #1
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    VBA Apply Formatting To Sheets With Specific Name

    Hi, I wonder whether someone can help me please.

    I've put together the following code which performs the following:

    • Find the sheets in the workbook which are not called "Launch Sheet", "All Data", or "All Resources", then
    • If the sheet name equals the value in column B on the "All Data" sheet, then
    • Apply formatting to the sheets.


    Please Login or Register  to view this content.
    The code runs without throwing an error, but the formatting isn't applied to the sheets, and I'm not sure why.

    I just wondered whether someone may be able to look at this please and let me know where I've gone wrong?

    Many thanks and kind regards

    Chris

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Apply Formatting To Sheets With Specific Name

    Maybe?

    Please Login or Register  to view this content.
    Last edited by JOHN H. DAVIS; 08-25-2014 at 11:13 AM.

  3. #3
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Apply Formatting To Sheets With Specific Name

    Hi @John H Davis, thank you for taking the time to come back to me with this.

    I've looked at, and tried to code but unfortunately I can't get this to work.

    I've taken the 'Next ws' out at the end of the script because I thought might be the cause, but sadly there appear to other issues I'm running into, which I hope you may be able to help me with please.
    • In If rng.Value <> "Launch Sheet" And rng.Value <> "All Data" And rng.Value <> "All resources" Then you set the search to find these names in the rng. value but these are the sheet names,
    • In the this line With Sheets(rng.Value), forgive me because this could be my lack of knowledge, but it doesn't seem to compare the sheet name to the rng.value

    Many thanks and kind regards

    Chris

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Apply Formatting To Sheets With Specific Name

    Can you attach a sample with a few sheet names?

    You request - " If the sheet name equals the value in column B on the "All Data" sheet, then

    Apply formatting to the sheets."

    We may need an Error handler it there is the possibility that the sheet does not exist, but With Sheets(rng.Value) should operate on a sheet if the name is the same as the rng value.

    If you can attach a sample then perhaps we can see why it is not working.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Apply Formatting To Sheets With Specific Name

    Perhaps.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Apply Formatting To Sheets With Specific Name

    Hi @John H Davis, as requested, please find attached a link to the file. I've had to put this in my "Dropbox" file because the file is 1.5MB. https://www.dropbox.com/s/t36n4oz352...0Test.xls?dl=0

    The procedure which I'm looking to change is called "ForecastsSheetHeaders".

    Many thanks and kind regards

    Chris
    Last edited by hobbiton73; 08-25-2014 at 01:13 PM.

  7. #7
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Apply Formatting To Sheets With Specific Name

    Hi @Norie, thank you very much for taking the time to reply to my post with the amended script.

    I've run the script but unfortunately I receive a subscript out of range error on this line: Set ws = Sheets(rng.Value)

    Many thanks and kind regards

    Chris
    Last edited by hobbiton73; 08-25-2014 at 01:14 PM.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Apply Formatting To Sheets With Specific Name

    Chris

    That usually means there's no sheet with the specified name.

    By the way, some people are reluctant to download from external sites.

    Can you upload the file here?

    If it's too big then you can either zip it or upload a cutdown version.

    PS I did download the file and the code I posted works without error.

  9. #9
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Apply Formatting To Sheets With Specific Name

    Hi @Norie, thank you for coming back to me with this.

    I fully appreciate your comments re. the download, I was wondering whether people may have issues with this. In terms of a cut down version, this is, unfortunately the cut down version, so I'm not sure I could reduce it further.

    I too was able to get your macro to work in the test file I sent, but when I used it in my full version I received the error.

    So I looked at this a little more and realised there as some erroneous data on the "All Data" sheet which I've now removed and it works perfectly, thank you.

    All the best and kind regards

    Chris
    Last edited by hobbiton73; 08-25-2014 at 01:50 PM.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Apply Formatting To Sheets With Specific Name

    Try:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Apply Formatting To Sheets With Specific Name

    Hi @John H Davis, thank you very much for coming back to me so quickly with this.

    The script works perfectly, thank you very much.

    All the best and kind regards.

    Chris

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Apply Formatting To Sheets With Specific Name

    You're welcome. Glad to help out and thanks for the feedback and the rep.

+ 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. [SOLVED] VBA Apply Formatting To Sheets
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-20-2013, 01:30 PM
  2. [SOLVED] Add border & apply conditional formatting to sheets based on cell value
    By amar05 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2013, 11:02 AM
  3. Replies: 4
    Last Post: 01-11-2010, 01:07 PM
  4. Locate row above cell with specific text, and apply formatting?
    By HelenW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2009, 11:09 AM
  5. VBA Code to find and apply formatting to specific text strings
    By chozen86 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-22-2008, 01:20 AM

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