Highlight the current worksheet selection with a color of your choice ?

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,806
Office Version
  1. 2016
Platform
  1. Windows
I am trying to give the current highlighted selection a certain interior color depending on certain conditions as the user drags the mouse or presses Shift+Arrow keys.

I know, by default, excel highlights the current selection by delimiting the selected area but I am looking to give the selection a bright color as well.

Any one got any ideas ?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
The below will work using Shift+cursor, but dragging doesn't take effect until the mouse button has been pressed.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Application
    .ScreenUpdating = False
    .EnableEvents = False
End With

Cells.Interior.ColorIndex = 0
Target.Interior.ColorIndex = 6

With Application
    .ScreenUpdating = True
    .EnableEvents = True
End With

End Sub
 
Upvote 0
Thanks for the quick response Neil.

the code doesn't take effect until the mouse left button has been released which is the limitation I am trying to overcome. I want the color to change dynamically ie : while the selection is being drawn.
 
Upvote 0
I guess this cannot be done .It seems that during a selection operation,the application enters a mode and becomes irresponsive which prevents from setting any Properties of any excel class (in this case the Interior.Color Property ).

Retrieving Properties does work however so ,in theory, one could retrieve the selection screen rectangle via the selection address property and paint the rectangle area with some GDI apis but that would be too much work I guess.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

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