Conditional Formatting - Single Column

     

  • Conditional Formatting single Column
  •  

    Private Sub CommandButton1_Click()
    Dim Last As Integer
    Last = Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
    Dim i As Integer
    For i = 1 To Last
    If Cells(i, 1) = "Apple" Then
    Cells(i, 1).Interior.ColorIndex = 3
    End If
    Next

     

     

    End Sub
    Private Sub CommandButton2_Click()
    UsedRange.Interior.ColorIndex = xlNone
    End Sub

     

     

    Conditional Formatting - Multiple Column

     

    Private Sub CommandButton1_Click()
    Dim Last As Integer
    Last = Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
    Dim i As Integer
    Dim c As Integer
    For i = 1 To Last
    If Cells(i, 1) = "Apple" Then
    c = Range(Cells(i, 1), Cells(i, 1).End(xlToRight)).Columns.Count
    Range(Cells(i, 1), Cells(i, c)).Interior.ColorIndex = 3
    End If
    Next
    End Sub

     

     

    Private Sub CommandButton2_Click()
    UsedRange.Interior.ColorIndex = xlNone
    End Sub

     

     

     

     

    Multiple Columns & Multiple Colors

     

    Private Sub CommandButton1_Click()
    Dim Last As Integer
    Last = Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
    Dim i As Integer, c As Integer
    For i = 1 To Last
    'Formatting for GRAPES
    If Cells(i, 1) = "Apple" Then
    c = Range(Cells(i, 1), Cells(i, 1).End(xlToRight)).Columns.Count
    Range(Cells(i, 1), Cells(i, c)).Interior.ColorIndex = 3
    End If
    'Formatting for BANANA
    If Cells(i, 1) = "Banana" Then
    c = Range(Cells(i, 1), Cells(i, 1).End(xlToRight)).Columns.Count
    Range(Cells(i, 1), Cells(i, c)).Interior.ColorIndex = 4
    End If
    'Formatting for ORANGE
    If Cells(i, 1) = "Orange" Then
    c = Range(Cells(i, 1), Cells(i, 1).End(xlToRight)).Columns.Count
    Range(Cells(i, 1), Cells(i, c)).Interior.ColorIndex = 5
    End If
    'Formatting for ERASER
    If Cells(i, 1) = "Eraser" Then
    c = Range(Cells(i, 1), Cells(i, 1).End(xlToRight)).Columns.Count
    Range(Cells(i, 1), Cells(i, c)).Interior.ColorIndex = 7
    End If
    'Formatting for BROWSER
    If Cells(i, 1) = "Browser" Then
    c = Range(Cells(i, 1), Cells(i, 1).End(xlToRight)).Columns.Count
    Range(Cells(i, 1), Cells(i, c)).Interior.ColorIndex = 8
    End If
    Next
    End Sub

     

     

     

    Private Sub CommandButton2_Click()
    'Remove Formatting for all
    UsedRange.Interior.ColorIndex = xlNone
    End Sub

     

     

     

    Conditional Formatting - Top10

     

    Private Sub CommandButton1_Click()
    Dim g As Variant
    Set g = Range("A1:A70").FormatConditions.AddTop10()
    g.Interior.ColorIndex = 5
    End Sub

     

     

     

    Conditional_Formatting_EXACT_Function

     

     

     

    Conditional_Formatting_Different_Examples