+ Reply to Thread
Results 1 to 4 of 4

Conditional formatting "applies to"

Hybrid View

  1. #1
    Registered User
    Join Date
    01-21-2014
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    74

    Conditional formatting "applies to"

    Using VBA, I want to conditionally format rows A to G if there is any value in B.

    I thought it might be easy, but not for me. I can record a macro to format rows A to G, but don't really know how to do the "applies to" part.

    Thank you

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Conditional formatting "applies to"

    Try this...

        Range("A1").Select
        With Columns("A:G")
            .FormatConditions.Delete
            .FormatConditions.Add Type:=xlExpression, Formula1:="=$B1<>"""""
            .FormatConditions(1).Interior.ColorIndex = 36   'Yellow
        End With
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    01-21-2014
    Location
    Oregon, USA
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Conditional formatting "applies to"

    You make it look so obvious.

    I have a couple questions:
    Why Range ("A1"). Select?
    Why the four quotes (two sets)?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Conditional formatting "applies to"

    Quote Originally Posted by bentod View Post
    You make it look so obvious.

    I have a couple questions:
    Why Range ("A1"). Select?
    Why the four quotes (two sets)?
    You're welcome.

    In this case, it could have selected any cell in row one. The column B row in this CF formula ("=$B1<>""""") is relative to active cell. As a test, select a different row to see what happens to the CF formulas.

    The CF formula in VBA is a string surrounded by two quotes; "=$B1<>"""""
    To represent one literal quote within a string in VBA, use two quotes. The formula needed two literal quotes. Thus four quotes in VBA.

+ 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. Conditional formatting by testing for "True" or "False"
    By Excel_vba in forum Excel General
    Replies: 2
    Last Post: 02-21-2014, 11:26 PM
  2. Replies: 2
    Last Post: 02-05-2013, 02:35 PM
  3. Replies: 2
    Last Post: 08-17-2012, 05:10 AM
  4. Replies: 2
    Last Post: 03-09-2010, 01:25 PM
  5. excel should "paste special" a "conditional formatting"
    By lozturk21 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-23-2005, 10:05 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