Conditional formatting for cell selection

Victtor

Board Regular
Joined
Jan 4, 2007
Messages
170
Office Version
  1. 365
Platform
  1. Windows
On my spreadsheet, is there a way I can highlight certain cells based on a selected cell?

Basically, if I choose any cell between E3:E28 then the corresponding cells on that row from columns F3:AG28 will highlight in Blue?

for example:

I select cell E15. then all the cells in the column range would highlight in blue (F15, G15, H15, ...AG15)

another example:

I select cell E25. then all the cells in the column range would highlight in blue (F25, G25, H25, ...AG25)


(just in case I am not clear, I "select" the cell by clicking on the cell)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try this in your worksheet code

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("E3:E28")) Is Nothing Then
        Range("F" & Target.Row & ":AG" & Target.Row).Interior.Color = vbCyan
    End If
End Sub
 
Upvote 0
Try this in your worksheet code

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("E3:E28")) Is Nothing Then
        Range("F" & Target.Row & ":AG" & Target.Row).Interior.Color = vbCyan
    End If
End Sub
You might want to modify your code so that the color fill doesn't persist after another selection:
Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Range("F3:AG28").Interior.Color = xlNone
    If Not Intersect(Target, Range("E3:E28")) Is Nothing Then
        Range("F" & Target.Row & ":AG" & Target.Row).Interior.Color = vbCyan
    End If
End Sub
 
Upvote 0
Thanks JoeMo and Sericom! This worked like a charm!!!
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,859
Members
449,472
Latest member
ebc9

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