chazzerman01
Board Regular
- Joined
- Nov 18, 2019
- Messages
- 65
does anyone know a macro code that will highlight the whole row that the cursor is on. im using it to make it easier to read values in a table
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'----------------------------------------------------------------
Application.ScreenUpdating = False
Cells.FormatConditions.Delete
With Target
With .EntireRow
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
With .FormatConditions(1)
With .Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
'.ColorIndex = 5
End With
With .Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
'.ColorIndex = 5
End With
'row color
.Interior.Color = RGB(245, 245, 245)
End With
End With
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
'cell color
'.FormatConditions(1).Interior.Color = RGB(255, 255, 0)
End With
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Application
.EnableEvents = False
.Goto .Union(Target.EntireRow, Target.EntireColumn)
.EnableEvents = True
End With
Target.Activate
End Sub
I tried your suggestion but did not like all the jumping around. I like solution in post 2@KOKOSEK, wouldn't that delete any pre-existing conditional formatting as well?
Also, applying CF to an entire row is most likely going to promote file bloat.
Not as good in terms of visibility, but a simpler method
VBA Code:Private Sub Worksheet_SelectionChange(ByVal Target As Range) With Application .EnableEvents = False .Goto .Union(Target.EntireRow, Target.EntireColumn) .EnableEvents = True End With Target.Activate End Sub
Public OldTarget As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
With OldTarget.EntireRow.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Target.EntireRow.Interior.Color = RGB(255, 255, 0)
Set OldTarget = Target
End Sub
What jumping around? Apart from the addition of the column highlight and a different shade, there is no difference to the behaviour of the 2 methods.I tried your suggestion but did not like all the jumping around. I like solution in post 2
Maybe it's just because it's doing the column and the row.What jumping around? Apart from the addition of the column highlight and a different shade, there is no difference to the behaviour of the 2 methods.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Application
.EnableEvents = False
Target.EntireRow.Select
Target.Activate
.EnableEvents = True
End With
End Sub