+ Reply to Thread
Results 1 to 9 of 9

Applying Conditional Formatting to a Range in VBA (range is set by variables)

  1. #1
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Applying Conditional Formatting to a Range in VBA (range is set by variables)

    So, i'm writing a macro to take multiple CSV downloads and merge them to one worksheet so it can be audited. However, some of the data is incomplete so once the worksheet has been put together, i want to apply a conditional format to the range we have just created to highlight blank cells.


    My code is:

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Applying Conditional Formatting to a Range in VBA (range is set by variables)

    Please Login or Register  to view this content.
    Elegant Simplicity............. Not Always

  3. #3
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Applying Conditional Formatting to a Range in VBA (range is set by variables)

    Hi, thank you - i put Destrange.Select at the start of your code i no longer get the error.

    However, although the conditional format appears to have been set it a) only seems to be looking at cell F16 and b) and doesn't appear to alter the range.

    So i tried the below and still get run time error 5

    Please Login or Register  to view this content.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Applying Conditional Formatting to a Range in VBA (range is set by variables)

    I'm surprised your original code got as far as it did since you never assign a range to destrange
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Applying Conditional Formatting to a Range in VBA (range is set by variables)

    Thanks, i've tried defining the range both with your method:

    Please Login or Register  to view this content.
    and another method:

    Please Login or Register  to view this content.
    and it fails on this line for both:


    Please Login or Register  to view this content.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Applying Conditional Formatting to a Range in VBA (range is set by variables)

    you have to use Set when assigning a range object (or any object) to a variable

    the cf code ought to be
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Applying Conditional Formatting to a Range in VBA (range is set by variables)

    You need to specify a cell location within the formula. This would be the top left cell of your selection in relative format.

    Formula1:="=F16="""""

    Please Login or Register  to view this content.
    Last edited by AndyLitch; 04-12-2013 at 07:46 AM.

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Applying Conditional Formatting to a Range in VBA (range is set by variables)

    not if you are using xlcellvalue ;-)

  9. #9
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Applying Conditional Formatting to a Range in VBA (range is set by variables)

    Thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaankk You!

    It was the Extra """ that was throwing the syntax - i was banging my head on a brick wall over that one...

    Super Stars! Cheers guys

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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