Change row colors based on a cell value

J

JDaniel1127

Trying to change a row color based on the subtraction of 2 cells

Have the following code as a macro on an update button:

Sub Update_Row_Colors()

Dim LRow As Integer
Dim LCell As String
Dim LColorCells As String
'Start at row 2
LRow = 2
SCell = 1

'Update row colors for the first 2000 rows
While LRow < 2000
LCell = "H" & LRow
'Color will changed in columns A to G
LColorCells = "A" & LRow & ":" & "G" & LRow
'Color set to Red or Green
If Left(Range(LCell).Value, 6) >= 0 Then
Range(LColorCells).Interior.ColorIndex = 4
Range(LColorCells).Interior.Pattern = xlSolid
Else
Range(LColorCells).Interior.ColorIndex = 3
End If

If Left(Range(LCell).Value, 6) = "" Then
Rows(LRow & ":" & LRow).Select
Range(LColorCells).Interior.ColorIndex = xlNone
End If

LRow = LRow + 1
Wend

Range("A1").Select

End Sub

The sheet I am working with has column H as the sum(d3-e3) throug
sum(d100-e100. The problem is when the H column value is #value! i
stops with a runtime error '13' type mismatch. How do I fix that
 
I

isabelle

hi JDaniel,

you may add "On Error Resume Next" at the beginning of the loop

While LRow< 2000
On Error Resume Next

--
isabelle



Le 2012-03-26 20:59, JDaniel1127 a écrit :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top