ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Change row colors based on a cell value (https://www.excelbanter.com/excel-worksheet-functions/445601-change-row-colors-based-cell-value.html)

JDaniel1127

Change row colors based on a cell value
 
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) through sum(d100-e100. The problem is when the H column value is #value! is stops with a runtime error '13' type mismatch. How do I fix that?


All times are GMT +1. The time now is 03:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com