+ Reply to Thread
Results 1 to 8 of 8

Conditional Formatting via VBA

  1. #1
    Registered User
    Join Date
    10-21-2015
    Location
    UK
    MS-Off Ver
    2003
    Posts
    9

    Conditional Formatting via VBA

    Hi all,

    I have written the VB below to apply conditional formatting on a large selection of cells in Column B:

    Please Login or Register  to view this content.
    But, this causes the worksheet to hang as it applies it to 9996 cells all the time. Is there a way to smarten this up to apply to the whole of Column B, but only the cells that have values in them?

    Thanks in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    Re: Conditional Formatting via VBA

    Maybe change your first line to work only with those cells that are affected (the 'target' cells of column B's range)

    Please Login or Register  to view this content.
    ______________________

    Some other tips to speed up the execution..

    1. Use DIM to declare the data type of each variable. Otherwise they are considered to be type 'Variant' and require more processing.

    2. Turn off screen updating at the start of your macro and restore it at the end. This can greatly improve the execution speed.

    Please Login or Register  to view this content.
    Last edited by StuCram; 10-23-2015 at 01:47 PM.
    If this has been helpful, please click on the star at the left.

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Conditional Formatting via VBA

    In addition, if you are going to be using the Worksheet_Change event you probably don't need the loop which will dramatically speed things up and reduce errors

    Please Login or Register  to view this content.
    If you are happy with my response please click the * in the lower left of my post.

  4. #4
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    Re: Conditional Formatting via VBA

    Hi stnkynts

    I think your "Next" statement should have been "End If"

    - Stu

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Conditional Formatting via VBA

    I think your "Next" statement should have been "End If"
    You are correct sir. Good catch.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-21-2015
    Location
    UK
    MS-Off Ver
    2003
    Posts
    9

    Re: Conditional Formatting via VBA

    I made the changes suggested (or at least, I tried to!) but I get an error. Here's what I now have. The first part of code relates to a different thread I had open.

    Please Login or Register  to view this content.
    The error is:
    Run-time error 91
    Object variable or with block variable not set


    on the line...

    Please Login or Register  to view this content.
    I'm guessing it's because I've not told that part of code what it's looking at (I used DIM on JobStatus, but then didn't mention it here?) but not sure how to correct - the suggested code differed in the two responses. Would you be able to help me a bit further? Thanks in advance.

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

    Re: Conditional Formatting via VBA

    Try changing these:

    Please Login or Register  to view this content.
    To:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-21-2015
    Location
    UK
    MS-Off Ver
    2003
    Posts
    9

    Re: Conditional Formatting via VBA

    Many thanks all

+ 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 Date or Text Values in a Conditional Formatting Formula
    By Phil Hageman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-15-2014, 09:36 AM
  2. Opening xlsm files with conditional formatting opens with removed conditional formatting
    By Martijn.Steenbakker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2014, 05:38 AM
  3. Replies: 1
    Last Post: 09-20-2013, 06:23 PM
  4. Delete Conditional Formatting conditions but keep cell formatting - Excel 2010
    By tetreama in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2012, 08:28 PM
  5. Replies: 3
    Last Post: 05-15-2012, 04:13 PM
  6. Macro for formatting fonts and cell colours - not Conditional Formatting
    By Kayaness in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-07-2011, 03:46 AM
  7. Replies: 2
    Last Post: 11-02-2007, 12:03 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