Consulting

Results 1 to 4 of 4

Thread: Using conditional FormatConditions Method

  1. #1

    Using conditional FormatConditions Method

    Hi All,

    The consensus seems to be to use a case select rather than the FormatConditions method to when conditionally formatting using VBA.

    I'm writing a macro to create a spreadsheet template that may then be populated with data. I wish to apply conditional formatting to a column of cells that will contain either "A", "B" or "C" and fill red, green or orange respectively. Unfortunately, I'm having a little trouble with what I think is a pretty straightforward syntax and hoped someone could suggest my error.

    I assumed that this line would be sufficient for the first condition:

    [VBA]Range("B4:B20").FormatConditions.Add(xlCellValue, xlEqual, "A").Interior.Color = RGB(255,0,0)[/VBA]

    however VBA reports a syntax error.

    Any suggestions would be greatly appreciated...it can't be this hard!

    Many thanks,
    Stuart

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    [vba]

    With Range("B4:B20")

    .FormatConditions.Add xlCellValue, xlEqual, "A"
    With .FormatConditions(1)

    .Interior.Color = RGB(255, 0, 0)
    End With
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Just the brackets!!!

    Thanks a lot Sir!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    No, more than that.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •