Run VBA from double clicking a cell

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
Is it possible to run a macro subroutine when double clicking on a cell contained in a worksheet?

what im thinking of is creating a subroutine that will filter data on a sheet and when the user double-clicks say "Cell A10" then macro would run
if they double-click "Cell A11" a different macro would run ect....

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You can do that like
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Not Intersect(Target, Range("A10:A12")) Is Nothing Then
      Select Case Target.Address(0, 0)
         Case "A10": Call Macro1
         Case "A11": Call Macro2
         Case "A12": Call Macro3
      End Select
   End If
End Sub
 
Upvote 0
Search for VBA Worksheet Event and then put this into the sheet object:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      
    With Target
       Select Case .Address
          Case "$A$10": Call Macro_1
          Case "$A$11": Call Macro_2
      End Select
   End With

   Cancel = True
End Sub
 
Last edited:
Upvote 0
Hi Danny

The simple answer is yes. Use the worksheet double-click event.
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Select Case Target.Address
Case "$A$10"
' call macro for A10 here
MsgBox "a10 clicked"
Case "$A$11"
' call macro for a11 here
MsgBox "a11 clicked"
Case Else

' any other cell double-clicked comes here and results in no action
Cancel = True
End Select
End Sub
Put this code in the worksheet macro area and amend as necessary. You can have as many case conditions as you like.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,915
Members
449,132
Latest member
Rosie14

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