troubleshooting Question

Highlight Cell with if Condition

Avatar of Cartillo
CartilloFlag for Malaysia asked on
Microsoft Excel
7 Comments2 Solutions440 ViewsLast Modified:
Hi Experts,

I would like to request Experts help to modify the attached code. At present, the script highlights cell at  “Number” column in red if the value at Column “DataB” cell  less than value at Column “DataA” cell. Now need to modify the condition, highlight cell in red at “Number” column if value at “DataB” cell is more than 0 but less than value at “DataA” column. Hope Experts will help me to modify this code. Attached as well the workbook for Experts perusal.




Sub ColorNumber()
Dim myCols As Range
Dim myCell As Range

    For Each myCols In Range("A1", Range("A1").End(xlToRight))
    
        If myCols.Value = "Number" Then
        
            For Each myCell In Range(Cells(2, myCols.Column), Cells(Rows.Count, myCols.Column).End(xlUp))
                If myCell.Offset(0, 2).Value <> myCell.Offset(0, 3).Value Then
                    myCell.Interior.Color = 225
                     
                Else
                    myCell.Interior.Color = -33
                End If
            Next myCell
        End If
    Next myCols
End Sub
ColorCode.xls
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros