Shading a cell range based on where the user is typing

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Can I have a range of cells (B9:G9) highlight if any cell within that range is being clicked on or typed into? I would want to apply this to rows 9:67.

Thanks,
Andrew
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Can I have a range of cells (B9:G9) highlight if any cell within that range is being clicked on or typed into? I would want to apply this to rows 9:67.

Thanks,
Andrew
Try this: Right-click on the worksheet tab and select 'View Code'. In the VBE window that opens, paste the code below. Then close the VBE window and save the workbook.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = Range("B9:G67")
If Not Intersect(Target, rng) Is Nothing Then
    rng.Interior.ColorIndex = 6
End If

End Sub
You can change the color index number in the code to get the fill color you want.
 
Upvote 0
Ok, that is close, but when I select a cell I only want those cells in that row within the range to be highlighted and when I click a different cell the highlighted cell should no longer be highlighted, and if necessary new cells would be highlighted if within the parameters.

Sorry to make things so tricky, I am not very good with this aspect of excel.

Many Thanks,

Andrew
 
Upvote 0
Ok, that is close, but when I select a cell I only want those cells in that row within the range to be highlighted and when I click a different cell the highlighted cell should no longer be highlighted, and if necessary new cells would be highlighted if within the parameters.

Sorry to make things so tricky, I am not very good with this aspect of excel.

Many Thanks,

Andrew
Try this:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = Range("B9:G67")
rng.Interior.ColorIndex = xlNone
If Not Intersect(Target, rng) Is Nothing Then
    Range("B" & Target.Row, "G" & Target.Row).Interior.ColorIndex = 6
End If
End Sub
 
Upvote 0
So this one didn't seem to do anything at all. And is there any way to put in color codes differently as well?
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,633
Members
452,933
Latest member
patv

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