Link to home
Start Free TrialLog in
Avatar of Cartillo
CartilloFlag for Malaysia

asked on

Highlight Cell with if Condition

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

Open in new window

ColorCode.xls
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Cartillo - at the moment that code appears to fill the cell if DataA does not equal DataB, not if DataB is less than DataA.
SOLUTION
Avatar of Gemstorm
Gemstorm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For your question as given though, change line 10 to

If myCell.Offset(0, 3).Value > 0 And myCell.Offset(0, 2).Value > myCell.Offset(0, 3).Value Then

Open in new window

Avatar of Cartillo

ASKER

Hi StephenJR,

Thanks a lot for the revised code. Need one more help, highlight the  data in yellow if the DataB is 0. Hope you'll consider this request.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi StephenJR,

Thanks for the help
Hi StephenJR,

I need your help with this Q, kind of complicated to achieve the desired result.  

https://www.experts-exchange.com/questions/27249118/Copy-Data-at-the-variety-time.html