Worksheet Change Event - Colour infill cells

D

dd

Hi,

I'm using the following to highlight some cells in my row if the cell in
column 9 contains data.
How do I remove the colour if/when the data is then deleted?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Long, v As Variant
Dim cel As Range
Dim rng As Range
On Error GoTo errExit

Set rng = Intersect(Range(Range("I1"), _
Cells(Range("I500").End(xlUp).Row, 7)), Target)

If Not rng Is Nothing Then
For Each cel In rng
x = 0
With cel
If .Column = 9 Then 'col I

If .Value = "" Then
x = xlNone
Else
x = .Offset(0, -4).Interior.ColorIndex 'col B
End If
If .Interior.ColorIndex <> x Then
.Interior.ColorIndex = x
End If

With .Resize(1, 14)
v = .Interior.ColorIndex
If IsNull(v) Then v = -1
If v <> x Then
.Interior.ColorIndex = x
End If
End With
End If

If x Then
End If
End With
Next
End If
errExit:
End Sub

Regards
D Dawson
 
G

Guest

below the line

Set rng = Intersect(Range(Range("I1"), _
Cells(Range("I500").End(xlUp).Row, 7)), Target)


add the line

rng.interior.ColorIndex = xlNone
 

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