View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Peter Rooney Peter Rooney is offline
external usenet poster
 
Posts: 325
Default Prevent error when deleting row within Worksheet_Change target ran

Good afternoon, all,

I posted this problem earlier, but perhaps didn't explain it too well.

I have a database in columns B:D and I use the following event code to
change the interior colour of a data row, based on the value entered into
column D of that row. (named "ColorIndexCol" - D5:D59)

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Intersection As Range
Set Intersection = Intersect(Target, Range("ColorIndexCol"))
If Not Intersection Is Nothing Then
If Not Target Is Nothing Then
Target.Offset(0, -2).Resize(1, 3).Interior.ColorIndex =
Target.Value
End If
End If
End Sub

Whilst this works fine, if I delete any row between 5 and 59 i.e. within the
"ColorIndexCol" range), I get the error "Aplication defined or object defined
error", highlighting the "target.offset... line.

As you can see, I've tried to trap the error by using if not target is
nothing, but it doesn't work. Does anyone know how I can resolve this, please?

Thanks in advance

Pete