Insert Row colors the complete Row

R

robert morris

I use the following code to highlight the last entry in a row.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("F4:Y75")) Is Nothing Then
Range("F" & Target.Row & ":Y" & Target.Row).Cells. _
Interior.ColorIndex = xlColorIndexNone
Target.Cells.Interior.Color = vbYellow
End If
End Sub

Problem is, when a Row is inserted, the complete row is Yellow. I have no
Conditional Formating in use.

All I can figure is, it must be in the code.

Bob
 
M

Mike H

Bob,

This should cure the colour the entire row bit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Range("F4:Y75")) Is Nothing Then
Range("F" & Target.Row & ":Y" & Target.Row).Cells.Interior.ColorIndex =
xlColorIndexNone
Target.Cells.Interior.Color = vbYellow
End If
End Sub

Mike
 
R

robert morris

Mike,

Thanks, it get rid of the entire row bit but, I get an error box which says;
Compile Error
Syntax Error

And the line below is highlighted in the code, and it no longer highlights
the last entry anywhere on the sheet.

Range("F" & Target.Row & ":Y" & Target.Row).Cells.Interior.ColorIndex =

Bob
 
M

Mike H

Bob,

That's just line wrap, the 2 line below should be one but have wrapped in
the post

Range("F" & Target.Row & ":Y" & Target.Row).Cells.Interior.ColorIndex =
xlColorIndexNone

Mike
 
D

Don Guillett

Try this to insert
Sub insertrownocolor()
Rows(ActiveCell.row).Insert
Rows(ActiveCell.row).Interior.ColorIndex = 0
End Sub
 
B

Bob Phillips

NG word wrap. The bit on the next line should be part of that line.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
R

robert morris

Mike,

I corrected the wrap and all is well. Thanks a million/billion!

Bob
 

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