Double Click to activate a macro

DrDebit

Board Regular
Joined
May 20, 2013
Messages
123
Office Version
  1. 365
Platform
  1. Windows
Is it possible to have several different formulas of conditional formatting in a cell, but they will not occur until the cell is double-clicked?

Thank you!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Sure a Vba script can be activate using a Double Click.
But we do not need to use Conditional formatting.

So when you double click on A1 for example what do you want to happen.

Tell me where you want to double click and when you do so what do you want to happen.
Here is a example of a Double Click Script.

If you double click on any cell in column A if the value in the cell is 2 the cell color will be Blue

If you double click on any cell in column A if the value in the cell is 5 the cells color will be Red

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified  8/16/2019  3:07:17 AM  EDT
If Target.Column = 1 And Target.Value <> "" Then
    Cancel = True
        With Target.Interior
        
            Select Case Target.Value
                Case 2
                    .ColorIndex = 5
                Case 5
                    .ColorIndex = 3
            End Select
        End With
End If
End Sub
 
Upvote 0
Thank you so much for trying to help me.
I pasted your macro in a blank worksheet, but it didn't work...not sure what I am doing wrong...

I have written 4 macros, to change the color of the fill for a cell based on the user's needs (it is part of a game). However, I thought it would be easier to have the user double click and depending on the cell address with a vlookup, will change the cell to the right color.

Again, thank you for trying to help.
 
Upvote 0
Did you double click on a 5 in column A

Or Double click on a 2 in column A

??

That is what my script requires as per my original post.

This is a example since you never said what you want to double click on and never said what you wanted to happen.


To get specific help you have to provide specific details.
 
Upvote 0
When I double click in one of the cells, I go to edit mode, but nothing else happens.

Thank you so much.
 
Upvote 0
A asked you this:
Did you double click on a 5 in column A

Or Double click on a 2 in column A

And you did not answer me.

This might not do what you wanted but your original post was very vague about what you wanted.
 
Upvote 0
I also asked this question:
So when you double click on A1 for example what do you want to happen.

Tell me where you want to double click and when you do so what do you want to happen.

If your not willing to answer these questions I'm not able to help you.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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