+ Reply to Thread
Results 1 to 3 of 3

Simple True/False Colouring (Not Conditional)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Simple True/False Colouring (Not Conditional)

    I'm looking for a slightly better way of doing the following...

    Sub FalseTrueTest2()
    
        Dim cl As Range
        For Each cl In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
            Select Case cl.Value
                Case Is = "True"
                    cl.Style = "Good"
                Case Is = "False"
                    cl.Style = "Bad"
            End Select
        Next
        
    End Sub
    Last edited by Hyflex; 02-13-2012 at 11:12 AM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Simple True/False Colouring (Not Conditional)

    Hyflex,

    I would recommend conditional formatting instead of VBA. highlight column A and create two conditional format formulas:
    For the Good style, use this formula: =AND($A1<>"",$A1="True")
    For the Bad style, use this formula: =AND($A1<>"",$A1="False")
    Last edited by tigeravatar; 02-13-2012 at 11:41 AM.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Simple True/False Colouring (Not Conditional)

    I do see in your thread title that it says "(Not Conditional)". If it has to be VBA, I'd recommend using autofilter for this operation:
    Sub FalseTrueTest2()
        
        On Error Resume Next
        Application.ScreenUpdating = False
        
        With Range("A1", Cells(Rows.Count, "A").End(xlUp))
            .AutoFilter 1, "True"
            .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Style = "Good"
            
            .AutoFilter 1, "False"
            .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Style = "Bad"
            
            .AutoFilter
        End With
        
        Application.ScreenUpdating = True
        
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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