Highlight Row VBA Toggle command

steveh8204

Board Regular
Joined
Aug 20, 2018
Messages
143
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.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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:
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,037
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top