Interior color disappears

R

Rob Severijns

I Use the following code to set the interior color af a cell:


Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Application.ScreenUpdating = False

If Not Intersect(Target, Range("$M6:$M1006")) Is Nothing Then

With Target

Select Case .Value
Case Is = "Nld", "Bel"
.Offset(0, -11).Resize(1, 3).Interior.ColorIndex = 35
Case Else
.Offset(0, -11).Resize(1, 3).Interior.ColorIndex = xlNone
End Select

End With
End If

End Sub


and this to color a selected row:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Application.ScreenUpdating = False

If Intersect(ActiveCell, Range("B6:AO1006")) Is Nothing Then Exit Sub

Dim RngRow As Range
Dim RngCol As Range
Dim RngFinal As Range
Dim Row As Long
Dim Col As Long

Range("A1:IU6").Cells.Interior.ColorIndex = xlNone
Range("B6:IU1006").Cells.Interior.ColorIndex = xlNone

Row = Target.Row
Col = Target.Column

Set RngRow = Range("B" & Row, Range("AO" & Row, Target))
Set RngCol = Range(Cells(1, Col), Target)
Set RngFinal = RngRow

RngFinal.Interior.ColorIndex = 36

Range("B4:AO5").Cells.Interior.ColorIndex = 35

End Sub


Unfortunatly, when I select another cell or row the color, set by the first
part of the code, disappears.

Q:
What would the code be to make sure that I don't loose the interior color if
the conditions in the first part of the code are met and also make sure that
the entire row is colored when the condition is not met.



With kind regards.

Rob Severijns
 
T

The Code Cage Team

In the beginning of the row code you are setting whole ranges of rows
back to xlNone, so everytime you run this code all those rows are reset,
to check if thats your problem use ' before each line and then run the
code and see what happens.


--
The Code Cage Team

Regards,
The Code Cage Team
http://www.thecodecage.com
 
R

Rob Severijns

Thanks for your comment.
So far I've tried all kind of solutions but I just can't get it right.
Can you help me out here?

With kind regards,

Rob Severijns
 

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