+ Reply to Thread
Results 1 to 10 of 10

VBA to apply conditional format

  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    VBA to apply conditional format

    Hi all,

    I am applying several conditional formats to a sheet with macros. All of them are set up successfully but the one below:

    Please Login or Register  to view this content.
    I get a run-time error 1004. I assume there's too many ranges referenced? I tried Union(Range( as well, but no luck...

  2. #2
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: VBA to apply conditional format

    Try reducing the number of ranges and see if you get the error.

  3. #3
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to apply conditional format

    I tried before and it worked! Hence, I assume the number of ranges causes the error...

  4. #4
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: VBA to apply conditional format

    Is it possible there is a syntax error in one of the ranges?

  5. #5
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: VBA to apply conditional format

    I found on another forum that the number of ranges maximum is 16. (EDIT - may not be accurate on second look).

    And recommend using UNION to join the ranges.

  6. #6
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to apply conditional format

    Quote Originally Posted by kersplash View Post
    I found on another forum that the number of ranges maximum is 16. (EDIT - may not be accurate on second look).

    And recommend using UNION to join the ranges.
    Would using Union increase such a potential maximum?

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: VBA to apply conditional format

    The address that you pass to range can't be longer than 255 characters - yours is 392. Even if you remove the unnecessary $ signs you are left with 292, so you do need to union 2 ranges, or apply the CF in two blocks.

  8. #8
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to apply conditional format

    How would such a Union Range look like? I tried:

    Please Login or Register  to view this content.
    But it gets me a "Object doesn't support this property or method" error...

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: VBA to apply conditional format

    Union is not a worksheet property. You should use:

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: VBA to apply conditional format

    Thank you!! That works

+ 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] apply conditional format based 2 criterias
    By bdouglas1011 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-28-2017, 06:43 AM
  2. [SOLVED] How To Apply Conditional Format To Cell
    By Kingswood in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-09-2015, 12:59 PM
  3. apply conditional format to every 4th row
    By jlanderson18 in forum Excel General
    Replies: 2
    Last Post: 07-18-2013, 01:39 PM
  4. Only apply conditional format if cell val > 0
    By moorzee in forum Excel General
    Replies: 2
    Last Post: 05-10-2013, 05:02 PM
  5. Apply Conditional format only when cells are active?
    By bob63el in forum Excel General
    Replies: 3
    Last Post: 04-03-2013, 10:18 PM
  6. Replies: 9
    Last Post: 10-29-2012, 06:06 PM
  7. Conditional Format-apply to every row
    By hassankhan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2009, 03:24 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