Cell double click to change cell colour

trevolly

Board Regular
Joined
Aug 22, 2021
Messages
124
Office Version
  1. 365
Platform
  1. Windows
Hey all,

I'm wondering if anyone can help with a quick query?

Im currently setting up some vba that runs when you double click in a cell, changing the white background to green and then if you double click again it goes back to white. The only thing is that the "green" is v bright and I'd like it to be the third green down (from the top) in the default colour pallet. I've used a vba to identify the colour coding as "15" but when I replace the "vbGreen" in the coding it isn't the same colour (going black)

The coding is as....
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Time stamp
If Not Intersect(Target, Range("D3")) Is Nothing Then
Cancel = True
Target.Value = Now()
End If
'colour click
If Not Intersect(Target, Range("g25, G27,G29,G31,G33,G35,G37,G39,G41,G46,G48,G50,G52,G54,G56,G58")) Is Nothing Then
Cancel = True
Target.Interior.Color = IIf(Target.Interior.Color = vbWhite, vbGreen, vbWhite)
End If
End Sub

Thanks all
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    'Time stamp
    If Not Intersect(Target, Range("D3")) Is Nothing Then
        Cancel = True
        Target.Value = Now()
    End If
    'colour click
    If Not Intersect(Target, Range("g25, G27,G29,G31,G33,G35,G37,G39,G41,G46,G48,G50,G52,G54,G56,G58")) Is Nothing Then
        Cancel = True
        Target.Interior.ColorIndex = IIf(Target.Interior.ColorIndex = xlNone, 43, xlNone)
    End If
End Sub
 
Upvote 0
Solution

Try:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    'Time stamp
    If Not Intersect(Target, Range("D3")) Is Nothing Then
        Cancel = True
        Target.Value = Now()
    End If
    'colour click
    If Not Intersect(Target, Range("g25, G27,G29,G31,G33,G35,G37,G39,G41,G46,G48,G50,G52,G54,G56,G58")) Is Nothing Then
        Cancel = True
        Target.Interior.ColorIndex = IIf(Target.Interior.ColorIndex = xlNone, 43, xlNone)
    End If
End Sub
Thats a better colour and works! Thank you v much
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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