Highlighting row of active cell question

Highlighting row of active cell question

Post by S2V2SGFyZH » Mon, 15 Feb 2010 19:12:01


Hi,
I using the code below to highlight the row of the active cell, but if you
click in the highlighted row again it loses its highlight.
What I need is some form of code I think to say f the new active cell is
in the same row as the old cell, keep the highlightI just not good
enough at VBA to write it!


'Highlights the active cell row
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Excel.Range)
Static OldRng As Range
On Error Resume Next
Target.EntireRow.Interior.ColorIndex = 6
OldRng.EntireRow.Interior.ColorIndex = xlColorIndexNone
Set OldRng = Target
End Sub

Any ideas?
 
 
 

Highlighting row of active cell question

Post by TWlrZSB » Mon, 15 Feb 2010 19:21:01

Hi,

Try this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target
With .EntireRow
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
With .FormatConditions(1)
.Interior.ColorIndex = 20
End With
End With
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
End With
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.




> in the same row as the old cell, keep the highlightI just not good > > enough at VBA to write it!> > > > > > 'Highlights the active cell row> > Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target > > As Excel.Range)> > Static OldRng As Range> > On Error Resume Next> > Target.EntireRow.Interior.ColorIndex = 6> > OldRng.EntireRow.Interior.ColorIndex = xlColorIndexNone> > Set OldRng = Target> > End Sub> > > > Any ideas?> >

 
 
 

Highlighting row of active cell question

Post by S2V2SGFyZH » Mon, 15 Feb 2010 20:13:01

Thanks Mike. Works a treat!




> > in the same row as the old cell, keep the highlightI just not good > > > enough at VBA to write it!> > > > > > > > > 'Highlights the active cell row> > > Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target > > > As Excel.Range)> > > Static OldRng As Range> > > On Error Resume Next> > > Target.EntireRow.Interior.ColorIndex = 6> > > OldRng.EntireRow.Interior.ColorIndex = xlColorIndexNone> > > Set OldRng = Target> > > End Sub> > > > > > Any ideas?> > >
 
 
 

Highlighting row of active cell question

Post by TWlrZSB » Mon, 15 Feb 2010 20:36:01

Glad I could help and thanks for the feedback
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.






> > > in the same row as the old cell, keep the highlightI just not good > > > > enough at VBA to write it!> > > > > > > > > > > > 'Highlights the active cell row> > > > Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target > > > > As Excel.Range)> > > > Static OldRng As Range> > > > On Error Resume Next> > > > Target.EntireRow.Interior.ColorIndex = 6> > > > OldRng.EntireRow.Interior.ColorIndex = xlColorIndexNone> > > > Set OldRng = Target> > > > End Sub> > > > > > > > Any ideas?> > > >
 
 
 

Highlighting row of active cell question

Post by Don Guille » Mon, 15 Feb 2010 23:54:05

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.FormatConditions.Delete
With Target.EntireRow
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = 6
End With
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
XXXX@XXXXX.COM


> in the same row as the old cell, keep the highlightI just not good> > enough at VBA to write it!> >> >> > 'Highlights the active cell row> > Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target> > As Excel.Range)> > Static OldRng As Range> > On Error Resume Next> > Target.EntireRow.Interior.ColorIndex = 6> > OldRng.EntireRow.Interior.ColorIndex = xlColorIndexNone> > Set OldRng = Target> > End Sub> >> > Any ideas?> >