+ Reply to Thread
Results 1 to 8 of 8

VBA If Statement Formatting

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

    VBA If Statement Formatting

    Hi, I wonder whether someone can help me please.

    I'm trying to put together a small script (below) to format sheets within a given array.

    Please Login or Register  to view this content.
    The problem I'm having lies with this section of code:

    Please Login or Register  to view this content.
    As you can see, I'm trying to apply a certain set of formatting just to three of the sheets from the original array created at the beginning of the script, but I've clearly made an error because when I run this, I receive an error message.

    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 regards

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,420

    Re: VBA If Statement Formatting

    You've not closed the If block with an End If and you' ex not closed the For loop with a Next statement.


    Regards, TMS
    Last edited by TMS; 01-19-2014 at 10:53 AM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA If Statement Formatting

    and try this
    Please Login or Register  to view this content.
    instead of If ws.Value = Array("Monthly Direct", "Monthly Indirect", "Monthly Overheads") Then

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,420

    Re: VBA If Statement Formatting

    @nilem: the formatting is not the same for each range. Regards, TMS

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: VBA If Statement Formatting

    Hi, Trevor,

    Please Login or Register  to view this content.
    But I think the Select Case will only be part of the normal Loop. Another way could be to utilize a Boolean on the worksheet names and work with that.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

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

    Re: VBA If Statement Formatting

    Hi @TMShucks, thank you for taking the time to reply to my post, and my apologies for the typo.

    The original code should have been:

    Please Login or Register  to view this content.
    All the best and kind regards
    Last edited by hobbiton73; 01-19-2014 at 11:09 AM.

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

    Re: VBA If Statement Formatting

    HI @HaHOBe, thank you for taking the time to reply to my post and for the code suggestion, it works great.

    All the best and kind regards

    Chris

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

    Re: VBA If Statement Formatting

    Hi @nilem, thank you for taking the time to reply to my post and for the suggested code.

    Unfortunately, this doesn't quite have the desired, but as you can see @HaHoBe has also kindly provided a solution.

    All the best and kind regards

+ 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. Formatting cells with an IF statement
    By Little mag in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-22-2013, 07:46 AM
  2. Conditional Formatting (IF statement)
    By Marmie2 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-09-2013, 11:39 PM
  3. Conditional Formatting/IF statement Help
    By DayHey23 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-18-2013, 12:37 PM
  4. IF statement using formatting criteria (NOT conditional formatting)
    By chelseasikoebs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2009, 01:57 AM
  5. IF statement to control formatting?
    By drdavidge in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-24-2008, 05:18 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