Highlight row from the active cell

mclambchop

New Member
Joined
Apr 29, 2014
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hello, I would like to highlight an entire row in a different colour if the use selects any cell within that row. I have cobbled together the code below which works but it doesnt select the entire row (where there is data, not the entire row) and it changes the colour of the entire column. Could someone help me change the code?


'Range(Cells(5, 10), Cells(5051, 8)).Interior.ColorIndex = xlNone
'If Target.Row >= 5 And Target.Row <= 5051 Then
' Cells(Target.Row, 8).Interior.ColorIndex = 1
'End If

'Range(Cells(5, 10), Cells(5051, 8)).Font.ColorIndex = 1
'If Target.Row >= 5 And Target.Row <= 5051 Then
' Cells(Target.Row, 8).Font.ColorIndex = 2
'End If
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

See if this is any use.

1. Select all the columns (entire columns) that you want to highlight rows in.

2. Use Conditional Formatting -> New rule.. -> Use a formula to determine ... -> Format values where this formula is true: =CELL("row")=ROW() -> Format... -> On the Fill tab select the colour you want** -> Ok -> Ok

3. Right click the sheet name tab and choose 'View Code'

4. Copy and Paste the code below into the main right hand pane that opens at step 3.

5. Close the Visual Basic window & test.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = True
End Sub

** When choosing a colour, better to choose a colour that is not already used on the worksheet. On the Fill tab if you go to 'More Colors...' it would be easy to make a colour unique for your sheet.

An advantage of this method it that even with the vba code involved, Excel's 'Undo' function is preserved.
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

See if this is any use.

1. Select all the columns (entire columns) that you want to highlight rows in.

2. Use Conditional Formatting -> New rule.. -> Use a formula to determine ... -> Format values where this formula is true: =CELL("row")=ROW() -> Format... -> On the Fill tab select the colour you want** -> Ok -> Ok

3. Right click the sheet name tab and choose 'View Code'

4. Copy and Paste the code below into the main right hand pane that opens at step 3.

5. Close the Visual Basic window & test.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = True
End Sub

** When choosing a colour, better to choose a colour that is not already used on the worksheet. On the Fill tab if you go to 'More Colors...' it would be easy to make a colour unique for your sheet.

An advantage of this method it that even with the vba code involved, Excel's 'Undo' function is preserved.
Thank you so much, worked a treat! I have updated my profile, thanks for the advice, appreciated
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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