Results 1 to 7 of 7

Thread: VBA Code for Highlighting Cells based on If then Rules

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    443
    Location
    Rules 6 and 8 are not conditional formatting, they are editing data. Find/Replace could fix Manufacturer column for all rows but need a VBA procedure to fix PlanType to all upper case.
    Then include code for row edit.

    Revision to target only edited row.
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r As Integer
    r = Target(1).Row
    SetHighlight r
    If IsEmpty(Cells(r, 25)) Then Cells(r, 25).Value = "Not Visible" 'Rule 6
    Cells(r, 17).Value = UCase(Cells(r, 17).Value) 'Rule 8
    End Sub
    
    Sub SetHighlight(r As Integer)
    Macro2 r, 16
    Macro2 r, 42
    Macro2 r, 43
    Macro2 r, 44
    If Cells(r, 16).Value = "Good" And Cells(r, 42).Value = 0 And Cells(r, 43).Value <= 10 Then
        Macro1 r, 16
        Macro1 r, 42
        Macro1 r, 43
    End If
    If Cells(r, 16).Value = "Good" And Cells(r, 42).Value = 1 And Cells(r, 44).Value <= 10 Then
        Macro1 r, 16
        Macro1 r, 42
        Macro1 r, 44
    End If
    End Sub
    
    Sub Macro1(r As Integer, c As Integer)
        With Cells(r, c).Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 65535
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    End Sub
    
    Sub Macro2(r As Integer, c As Integer)
        With Cells(r, c).Interior
            .Pattern = xlNone
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    End Sub
    Last edited by June7; 11-19-2022 at 12:10 PM.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Posting Permissions

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