Highlight a specific range from a row when a cell in that range is selected

aurora446

New Member
Joined
Mar 4, 2014
Messages
4
Hi, I am new so forgive any mistakes.

I have a table from column B to column M and row 8 to row 47.

What I would like is to highlight the row in that range if i selected a cell in that row.

So for example if I select M8, then cells B8:M8 would be highlighted, but if I was to select N8 or A1, nothing would be highlighted. However I have conditional formatting on one of the columns which I do not want to be overwritten by the highlighting.

Any help would be appreciated.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Any code that will highlight entire rows OR a continuous Range of cells in a row WILL overwrite any conditional formatting.
 
Upvote 0
aurora446,

Welcome to MrExcel.

You can achieve what you are wanting as the interior colour of a cell and it's conditional colours if they exist, are independent of each other.

So try this code in your sheet's code module.
Right click the sheet tab >> View Code >> and paste into the white space of the editor pane.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("B8:M47")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
Range("B8:M47").Interior.ColorIndex = -4142
Range("B" & Target.Row & ":M" & Target.Row).Interior.ColorIndex = 3  'edit   3  to give colour of choice
End Sub

Hope that helps.
 
Upvote 0
aurora446,

Welcome to MrExcel.

You can achieve what you are wanting as the interior colour of a cell and it's conditional colours if they exist, are independent of each other.

So try this code in your sheet's code module.
Right click the sheet tab >> View Code >> and paste into the white space of the editor pane.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("B8:M47")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
Range("B8:M47").Interior.ColorIndex = -4142
Range("B" & Target.Row & ":M" & Target.Row).Interior.ColorIndex = 3  'edit   3  to give colour of choice
End Sub

Hope that helps.

This is fantastic, thanks so much. It seems to change the whole table to a lighter colour fill though. Is there anyway to leave the rest of the table unchanged and just highlight the relevant row? Also is it possible that no row be highlighted if I select a cell outside of this range? Thanks so much again
 
Upvote 0
This is fantastic, thanks so much. It seems to change the whole table to a lighter colour fill though. Is there anyway to leave the rest of the table unchanged and just highlight the relevant row? Also is it possible that no row be highlighted if I select a cell outside of this range? Thanks so much again

What is the 'normal' colour of the table?
Select a 'normal' cell in the table, open the vb editor and if you cannot see the 'Immediate' Pane at the bottom then click View > Immediate Window.

Type ?ActiveCell.Interior.ColorIndex and hit return. Then the colour index will appear below.
 
Upvote 0
What is the 'normal' colour of the table?
Select a 'normal' cell in the table, open the vb editor and if you cannot see the 'Immediate' Pane at the bottom then click View > Immediate Window.

Type ?ActiveCell.Interior.ColorIndex and hit return. Then the colour index will appear below.


One column is 35 (b), the rest are 20 (c-m)
 
Upvote 0
Color index 35 renders light blue for me, exactly the same as color index 20.

So, if for you all your table cells are the same then use the following...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("B8:M47").Interior.ColorIndex = 35
If Intersect(Target, Range("B8:M47")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
Range("B" & Target.Row & ":M" & Target.Row).Interior.ColorIndex = 3
End Sub

If for you, column B renders a different colour to C:M then use......

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("B8:B47").Interior.ColorIndex = 35
Range("C8:M47").Interior.ColorIndex = 20
If Intersect(Target, Range("B8:M47")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
Range("B" & Target.Row & ":M" & Target.Row).Interior.ColorIndex = 3
End Sub

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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