Run time error with multiple conditional format

jrking

New Member
Joined
Mar 27, 2009
Messages
2
I use this code so that I can have more than the standard 3 conditional formats, however, when I delete a row I get run time error. Is there any way to avoid the run time error?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("K:K")) Is Nothing Then
Select Case Target
Case "Zita Powell/Christa Collins"
 
Target.EntireRow.Select
Selection.Interior.ColorIndex = 8
icolor = 8
 
Case "Bo Hinnant"
Target.EntireRow.Select
Selection.Interior.ColorIndex = 43
icolor = 43
Case "Quint/Ray"
Target.EntireRow.Select
Selection.Interior.ColorIndex = 6
icolor = 6
Case "Xavier"
Target.EntireRow.Select
Selection.Interior.ColorIndex = 15
icolor = 15
 
Case ""
Target.EntireRow.Select
Selection.Interior.ColorIndex = 2
icolor = 2
 
 
End Select
 
Target.Interior.ColorIndex = icolor
End If
End Sub


Thanks

John
 
Last edited by a moderator:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
perhaps try this modification. as an fyi you don't need to SELECT items to work with them in vba. Also I wasn't sure why you were changing the row color inside the select case statement then again outside of the select case statement so I changed the above code to do it only once (on the outside):

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
Dim icolor As Integer
 
If Target.Column = 11 Then
 
    Select Case Target
 
    Case "Zita Powell/Christa Collins"
    icolor = 8
 
    Case "Bo Hinnant"
    icolor = 43
 
    Case "Quint/Ray"
    icolor = 6
 
    Case "Xavier"
    icolor = 15
 
    Case ""
    icolor = 2
 
    End Select
 
    Target.EntireRow.Interior.ColorIndex = icolor
 
End If
 
End Sub
 
Upvote 0
also, consider changing icolor = 0 for Case = "" (as opposed to '2'). Setting the color to '0' will clear all background color, which is what I'm assuming you wanted to do.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top