Highlight Row VBA Toggle command

steveh8204

Board Regular
Joined
Aug 20, 2018
Messages
119
Hi,

Is it possible to create code to highlight the row of the selected cell?



I use two screens so even if I select the whole row when I go to my second display excel doesnt show the highlighted row when I select a different window.



I was hoping it was also possible to have a macro that toggles this so I could set a shortcut key which will swicth this on and off as I select different rows.


Thanks in advance.
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,615
Hello,

This code will highlight the active row, from cols A - L.


Code:
Sub COLOUR_ROW()
    If Selection.Cells.Count > 1 Then End
        With ActiveSheet
            .Rows("1:65536").Interior.ColorIndex = xlNone
            .Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 12)).Cells.Interior.ColorIndex = 36
        End With
End Sub
and this code will unhighlight all rows.

Code:
Sub UNCOLOUR_ROW()
    With ActiveSheet
        .Rows("1:65536").Interior.ColorIndex = xlNone
    End With
End Sub
This will affect any background coloured cells already created.

Change columns required as necessary, as well as colour. Not sure about the two screens, as I don't have this. But it may point you in the right direction.
 
Last edited:

steveh8204

Board Regular
Joined
Aug 20, 2018
Messages
119
Hello,

This code will highlight the active row, from cols A - L.


Code:
Sub COLOUR_ROW()
    If Selection.Cells.Count > 1 Then End
        With ActiveSheet
            .Rows("1:65536").Interior.ColorIndex = xlNone
            .Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 12)).Cells.Interior.ColorIndex = 36
        End With
End Sub
and this code will unhighlight all rows.

Code:
Sub UNCOLOUR_ROW()
    With ActiveSheet
        .Rows("1:65536").Interior.ColorIndex = xlNone
    End With
End Sub
This will affect any background coloured cells already created.

Change columns required as necessary, as well as colour. Not sure about the two screens, as I don't have this. But it may point you in the right direction.
This is perfect. It did affect current colouring but I just changed it to start at row 3 so its fine now.



It comes with the added bonus that when I select a new row it clears the previous row.



Thanks very much for your help with this.
 

Forum statistics

Threads
1,086,200
Messages
5,388,366
Members
402,115
Latest member
ypompoms

Some videos you may like

This Week's Hot Topics

Top