Cells to be highlighted when clicked

danjuma

Active Member
Joined
Sep 21, 2008
Messages
251
Hello,

What I want to be able to do is click any cell in columns A to F, and the rows for that particular cell will be highlighted (in say colour yellow), and becomes un-highlighted when I unclick from the cell. So basically, say I click cell C3, cells in the row A3:F3 will become highlighted, and the highlighting will disappear when I unclick from cell C3. I know, there are a few threads on highlighting cells, from searching through the forum, but I can't find one that specifically does what I want, and as I am not all that versed in VBA, I do not understand the most of the example codes, let alone trying to amend it to suit my needs.

Many thanks.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Right-click your sheet, left-click View Code and paste this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Columns("A:F")) Is Nothing Then 
Columns("A:F").Interior.Pattern = xlNone
Range("A" & Target.Row & ":F" & Target.Row).Interior.ColorIndex = 6
End If
End Sub

Warning: This will remove any prior highlighting in columns A - F.
 
Last edited:
Upvote 0
Paste this code into your Sheet Module

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column > 6 Then Exit Sub
Cells().Interior.ColorIndex = vbNone
Range(Cells(Target.Row, 1), Cells(Target.Row, 6)).Interior.ColorIndex = 6
End Sub
 
Upvote 0
In case you want it to work when you select multiple rows at the same time, this can be used:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Columns("A:F")) Is Nothing Then
Columns("A:F").Interior.Pattern = xlNone
For Each mycell In Target
    Range("A" & mycell.Row & ":F" & mycell.Row).Interior.ColorIndex = 6
Next
End If
End Sub
 
Last edited:
Upvote 0
Thank you everyone (syntaxed, jim may and jasonb75) for your assistance. Very much appreciated. I have settled for the solution in the link provided by jasob75. This is because this solution does not affect other conditional formats in other cells, and also the highlighting disappears (does not stay on when I unclick the cells it applies to).

Once more, many thanks everyone.
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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