Hi All, New here and a bit of a novice.
I want to be able to click on a cell eg. C9 and run 1 macro, Click on C10 and run another macro etc.
I would prefer not to have button.
What is the best way?![]()
Hi All, New here and a bit of a novice.
I want to be able to click on a cell eg. C9 and run 1 macro, Click on C10 and run another macro etc.
I would prefer not to have button.
What is the best way?![]()
This can be done with a Worksheet Event
Place this code into the Worksheet Module by right clicking on the sheet tab and selecting View Code, Paste the code there....
![]()
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$C$10" Then MsgBox "You Picked C10" 'your code goes here End If If Target.Address = "$C$11" Then MsgBox "You Picked C11" 'your code goes here End If If Target.Address = "$C$12" Then MsgBox "You Picked C12" 'your code goes here End If End Sub
Thanks very much for your help
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
_________________________________________
![]()
![]()
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
Hi
You can with this:
Alt+F11 and paste the following
Close the window. Double click and the macro will be executed.It's an example.![]()
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) Range("A1").Select Selection.Font.Bold = True End Sub
Last edited by Raiby; 01-18-2009 at 05:38 AM.
Ralby
Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
luffield,
You can use the Worksheet_SelectionChange Event to accomplish your request.
Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).
Right click the sheet tab you want the code in, and click on View Code. Paste the below code there (on the right pane).
![]()
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Intersect(Target, Range("C9:C10")) Is Nothing Then Exit Sub Application.EnableEvents = False If Target.Address = "$C$9" Then Call Macro1 ElseIf Target.Address = "$C$10" Then Call Macro2 End If Application.EnableEvents = True End Sub
Press and hold down the 'ALT' key, and press the 'F11' key.
On the 'Insert' menu, click 'Module'.
Copy the below code, and paste it into the Module (on the right pane).
![]()
Sub Macro1() MsgBox "Macro1 is running." End Sub Sub Macro2() MsgBox "Macro2 is running." End Sub
Then click on either cell C9 or C10.
Have a great day,
Stan
Last edited by stanleydgromjr; 01-17-2009 at 09:58 AM.
Have a great day,
Stan
Windows 10, Excel 2007, on a PC.
If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks