Consulting

Results 1 to 3 of 3

Thread: vba conditional formatting - compare range of adjacent cells

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Dec 2015
    Posts
    57
    Location

    vba conditional formatting - compare range of adjacent cells

    I need help with coding vba conditional formatting. I am trying to compare a column of numbers to each other and color the cells which do not match. Either color both cells or the cells in the right column (column J).

    I researched and attempted but got stuck and needed some help. Below is my code

    Sub AA450_CONDITIONAL1()
    Dim rg As Range
    Dim cond1 As FormatCondition
    'GET LAST ROW IN COLUMN J IN THE RECAP SHEET FOR THIS MACRO
    Dim Lastrow7 As Long
    Lastrow7 = Worksheets("RECAP").Columns("O").Find("*", SEARCHDIRECTION:=xlPrevious, SEARCHORDER:=xlByRows, LookIn:=xlValues).Row
    'SET THE RANGE
    Set rg = Range("J5:J" & Lastrow7)
    'clear any existing conditional formatting
    'rg.FormatConditions.Delete
    Worksheets("RECAP").Columns("J").FormatConditions.Delete
    Worksheets("RECAP").Activate
    'define the rule for each conditional format
    Set cond1 = rg.FormatConditions.Add(xlCellValue, xlEqual, "=$H$5:$H$" & Lastrow7)
    'define the format applied for each conditional format
    With cond1
    .Interior.Color = vbGreen
    .Font.Color = vbWhite
    End With
    End Sub
    Last edited by Aussiebear; 08-08-2018 at 03:13 PM. Reason: Tidied up the code presentation

Posting Permissions

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