Run macro on cell click

fatduck

New Member
Joined
Jun 26, 2008
Messages
13
Hi there

I have a maco written which operates on a relative reference from a specific cell; Activecell H5 will run the macro on cells B5:G5, and H10 will run the macro on cells B10:G10, etc.

The only problem is that I don't know how to run the macro from the cell!

I have the text "Find" in the relevant cells in Column H, and I'd like the user to be able to click/double-click on one of these H cells to run the macro on that row.

Can anyone please help?

Thanks!
Daniel
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try this in the worksheet module, (substitute your macro for "MyMacro")

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 8 _
And Target.Value = "Find" Then
Call MyMacro
End If
End Sub
 
Upvote 0
You'll probably want to feed the row variable to your macro so make the call as;

Call MyMacro(target.row)
 
Upvote 0
I would suggest you Cancel the double click:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 8 And UCASE(Target.Value) = "FIND" Then
     Call MyMacro(Target.Row)
     Cancel = True
End If
End Sub

The only issue with this approach will be how user attempts to edit contents of H (if they are allowed to). If the contents of H are dynamic and determine the actions of your macro you may want to put an InputBox into the above such that end-user double clicks cell, enters text via InputBox (which in turn is used in Macro and text is set in active cell).

Without knowing your exact setup it's difficult to advise but just somethings to be aware of.

HTH
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

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