Can you change a cell color just by clicking it?

donutboy

New Member
Joined
Aug 6, 2009
Messages
4
I would like to turn a group of cells red or green just by using mouse clicks. Click one time and it turns red, click it again it turns green. Is that possible?


If that is not possible I would like to turn them colors by entering "y" for yes = green and "n" for no = red.



Thanks you guys/gals:cool:
 
Peter_Ss, this works much better. Thank you.

One more thing, if I wanted to make it change on RightClick, would it be as simple as changing from DoubleClick to RightClick?
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi everyone. Thank you for your help thus far. I need to do a slight modification to what has been posted, but I can't figure out how to. On a given spreadsheet, I need the cells B5:B16 to turn green if I double click; the cells on C5:C16 to turn yellow if I double click; and the cells on D5:D16 to turn red. And as before, right click would remove the colour.
Is this possible? TIA
 
Upvote 0
the cells on C5:C16 to turn yellow if I double click
Welcome to the MrExcel board!

If you double-click on a single cell in C5:C16 do you want the whole 12 cells to turn yellow, or just the cell that was double-clicked?
Same for other ranges I assume.
 
Upvote 0
just the clicked cell
Then try this. Use double-click to add or remove colour from the cell

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Dim Clrs As Variant
  
  Clrs = Split("5296274 65535 255")
  If Not Intersect(Target, Range("B5:D16")) Is Nothing Then
    Cancel = True
    If Target.Interior.Color = 16777215 Then
      Target.Interior.Color = Clrs(Target.Column - 2)
    Else
      Target.Interior.Color = xlNone
    End If
  End If
End Sub
 
Upvote 0
Hello and welcome to MrExcel.

Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Interior.ColorIndex = 3
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Interior.ColorIndex = 4
End Sub

Press ALT + Q to return to your sheet. Double click a cell to turn it red or right click to turn it green.
Hello Vog Sir.. this code works for me in great way.. Thanks for always supporting us.. You're simple great.. ?
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,830
Members
449,190
Latest member
rscraig11

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