![]() |
Interior color disappears
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 |
Interior color disappears
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 ------------------------------------------------------------------------ The Code Cage Team's Profile: http://www.thecodecage.com/forumz/member.php?userid=2 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=29472 |
Interior color disappears
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 "The Code Cage Team" wrote: 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 ------------------------------------------------------------------------ The Code Cage Team's Profile: http://www.thecodecage.com/forumz/member.php?userid=2 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=29472 |
All times are GMT +1. The time now is 07:32 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com