ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   changing cell colour on click (https://www.excelbanter.com/excel-discussion-misc-queries/43325-changing-cell-colour-click.html)

Nimbus55

changing cell colour on click
 
I'd like to see a cell change colour when a user clicks it...How would I do
that?
Thanks

JE McGimpsey

Would you settle for a double-click?

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
Cancel = True
With Target.Interior
.ColorIndex = IIf(.ColorIndex = 3, xlColorIndexNone, 3)
End With
End Sub

You could do the same thing with a single click by using the
Worksheet_SelectionChange() event macro, but that would also be
triggered by tabbing, the Enter and arrow keys, etc.


In article ,
"Nimbus55" wrote:

I'd like to see a cell change colour when a user clicks it...How would I do
that?
Thanks


JE McGimpsey

Forgot to say that this should go in your worksheet code module
(right-click the worksheet tab and choose View Code)

In article ,
JE McGimpsey wrote:

Would you settle for a double-click?

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
Cancel = True
With Target.Interior
.ColorIndex = IIf(.ColorIndex = 3, xlColorIndexNone, 3)
End With
End Sub

You could do the same thing with a single click by using the
Worksheet_SelectionChange() event macro, but that would also be
triggered by tabbing, the Enter and arrow keys, etc.


Nimbus55

Thank you....it's perfect!

"JE McGimpsey" wrote:

Forgot to say that this should go in your worksheet code module
(right-click the worksheet tab and choose View Code)

In article ,
JE McGimpsey wrote:

Would you settle for a double-click?

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
Cancel = True
With Target.Interior
.ColorIndex = IIf(.ColorIndex = 3, xlColorIndexNone, 3)
End With
End Sub

You could do the same thing with a single click by using the
Worksheet_SelectionChange() event macro, but that would also be
triggered by tabbing, the Enter and arrow keys, etc.




All times are GMT +1. The time now is 10:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com