highlight of a range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a spreadsheet that has several hundred rows and 25 columns of info. I
would like to be able to highlight the entire row of information that the
cursur is in and the highlighted row moves as the cursur moves. I am not
sure how to do this please help

thanks
 
right click on the sheet tab and select view code

paste in code like this:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object,
ByVal Target As Excel.Range)
Static OldRange As Range
On Error Resume Next
Target.Entirerow.Interior.ColorIndex = 6 ' yellow - change as needed
OldRange.EntireRow.Interior.ColorIndex = xlColorIndexNone
Set OldRange = Target

End Sub

Adapted from code by Chip Pearson.

http://www.cpearson.com/excel/excelM.htm#HighlightActiveCell
 
Tom Ogilvy wrote
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object,
ByVal Target As Excel.Range)
Static OldRange As Range
On Error Resume Next
Target.Entirerow.Interior.ColorIndex = 6 ' yellow - change as needed
OldRange.EntireRow.Interior.ColorIndex = xlColorIndexNone
Set OldRange = Target

End Sub

Can you help me adapt your seemingly more efficient method to a limited
range of cells?

Code I currently use:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("I5:S55").FormatConditions.Delete
If Intersect(Target, Range("I5:S55")) Is Nothing Then Exit Sub
With Range(Cells(Target.Row, 9), Cells(Target.Row, 19))
..FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
..FormatConditions(1).Interior.ColorIndex = 6
End With
End Sub
 
David wrote
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("I5:S55").FormatConditions.Delete
If Intersect(Target, Range("I5:S55")) Is Nothing Then Exit Sub
With Range(Cells(Target.Row, 9), Cells(Target.Row, 19))
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
.FormatConditions(1).Interior.ColorIndex = 6
End With
End Sub

Was able to reduce to this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("I5:S55").Interior.ColorIndex = 2
If Intersect(Target, Range("I5:S55")) Is Nothing Then Exit Sub
Range(Cells(Target.Row, 9), Cells(Target.Row, 19)).Interior.ColorIndex = 6
End Sub

Works as desired.
 

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

Back
Top