Sei sulla pagina 1di 8

3/27/2018 How to trigger or run a Macro by clicking a specific cell in Excel?

 ExtendOffice (https://www.extendoffice.com)

 Office Tips & Tricks  Tips & Tricks for Excel  Tips & Tricks for Word  Tips & Tricks for Outlook
(/documents.html) (/documents/excel.html) (/documents/word.html) (/documents/outlook.html)

      
How To Trigger Or Run A Macro By Clicking A Specific Cell In Excel?
While working with Microsoft Excel, you may know how to run a certain Macro with a Command Button. But do you know how to run
a Macro by just clicking on a specific cell in a worksheet? This article will show you method of triggering a Macro by clicking on a
specific cell in details.

Trigger or run a Macro by clicking a specific cell with VBA code

Combine Multiple Worksheets/Workbooks Into One Worksheet / Workbook:

Combine multiple worksheets or workbooks into one single worksheet or workbook may be a huge task in your daily work. But, if
you have Kutools for Excel, its powerful utility – Combine can help you quickly combine multiple worksheets, workbooks into one
worksheet or workbook.

Kutools for Excel includes more than 120 handy Excel tools. Free to try with no limitation in 60 days. Download the free trial
now (https://d2d42mpnbqmzj3.cloudfront.net/downloads/KutoolsforExcelSetup.exe)

https://www.extendoffice.com/documents/excel/4354-excel-click-on-cell-to-run-macro.html#a1 1/8
3/27/2018 How to trigger or run a Macro by clicking a specific cell in Excel?

(https://d2d42mpnbqmzj3.cloudfront.net/downloads/KutoolsforExcelSetup.exe)

Recommended Productivity Tools

Office Tab: Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and new Internet Explorer.
(/product/office-tab.html) Try now (https://d2d42mpnbqmzj3.cloudfront.net/downloads/SetupOfficeTab.exe)

https://www.extendoffice.com/documents/excel/4354-excel-click-on-cell-to-run-macro.html#a1 2/8
3/27/2018
Kutools for Excel: 200 new features for Excel,How to trigger or run a Macro by clicking a specific cell in Excel?
make Excel much easy and powerful, increase productivity
immediately. (/product/kutools-for-excel.html)
Try now (https://d2d42mpnbqmzj3.cloudfront.net/downloads/KutoolsforExcelSetup.exe)

 Trigger Or Run A Macro By Clicking A Specific Cell With VBA Code

(/product/office-tab.html)

Amazing! Using Tabs In Excel Like Firefox, Chrome, Internet Explore 10! (/Product/O

The following VBA code can help you to run a Macro by clicking a specific cell in Excel. Please do as follows.

1. On the worksheet with the cell you need to click to run a Macro, right click the sheet tab, and then click View Code from the
context menu.

2. In the Microsoft Visual Basic for Applications window, copy and paste the below VBA script into the Code window.

VBA code: Trigger or run a Macro by clicking a specific cell

1 Option Explicit
2
3 Private Sub Worksheet_SelectionChange(ByVal Target As Range)
4 If Selection.Count = 1 Then
5 If Not Intersect(Target, Range("D4")) Is Nothing Then
6 Call MyMacro
7 End If
8 End If
9 End Sub
https://www.extendoffice.com/documents/excel/4354-excel-click-on-cell-to-run-macro.html#a1 3/8
3/27/2018 How to trigger or run a Macro by clicking a specific cell in Excel?
Notes:

1. In the code, D4 is the cell you will click to run Macro;

2. Please replace the code name MyMacro with the Macro you will run in the worksheet. See screenshot:

3. Press the Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window.

From now on, when clicking on cell D4 in current worksheet, your specified Macro will be triggered immediately.

 Related Articles:

How to pop up a calendar when clicking a specific cell in Excel? (/documents/excel/4346-excel-click-cell-popup-calendar.html)


How to change cell color when cell is clicked or selected in Excel? (/documents/excel/3635-excel-change-cell-color-when-
clicked-selected.html)
How to pop up message box when clicking on a certain cell in Excel? (/documents/excel/3832-excel-message-box-when-click-
on-cell.html)
How to disable button after clicking once in Excel? (/documents/excel/4288-excel-disable-button-after-click.html)
https://www.extendoffice.com/documents/excel/4354-excel-click-on-cell-to-run-macro.html#a1 4/8
3/27/2018
How to disable right click on sheet tab in Excel?How to trigger or run a Macro by clicking a specific cell in Excel?
(/documents/excel/4290-excel-disable-right-click-on-sheet-tab.html)

Recommended Productivity Tools

Office Tab (/Product/Office-Tab.Html)

Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and new Internet Explorer.

Kutools For Excel (/Product/Kutools-For-Excel.Html)

Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!
200 New Features for Excel, Make Excel Much Easy and Powerful:
Merge Cell/Rows/Columns without Losing Data.
Combine and Consolidate Multiple Sheets and Workbooks.
Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...

https://www.extendoffice.com/documents/excel/4354-excel-click-on-cell-to-run-macro.html#a1 5/8
3/27/2018 How to trigger or run a Macro by clicking a specific cell in Excel?

(/product/kutools-for-excel.html)

https://www.extendoffice.com/documents/excel/4354-excel-click-on-cell-to-run-macro.html#a1 6/8
3/27/2018 How to trigger or run a Macro by clicking a specific cell in Excel?
(/product/kutools-for-excel.html) (/download/kutools-for-
excel.html) (/order/kutools-for-excel.html)

7 Comments RSS (/component/jlexcomment/?view=items&com_name=content&com_key=4354&format=feed) Login

Sort by Newest b
Say something here...

PEOPLE IN CONVERSATION:

Wayne · 5 months ago

This worked perfectly and will save me a load of time - thank you for sharing your knowledge - much appreciated!
Reply Share

crystal · 5 months ago

I’m glad I could help.


Reply Share

Simon Jones · 5 months ago

If you want to have multiple macros, cells running different macros on the same page - is that possible?
Reply Share

crystal · 5 months ago

Dear Simon,
The below VBA script can help you to run different macros by clicking on cells on the same page.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)


If Target.Count = 1 Then
If Not Intersect(Target, Range("D4")) Is Nothing Then Call MyMacro1
https://www.extendoffice.com/documents/excel/4354-excel-click-on-cell-to-run-macro.html#a1 7/8
3/27/2018 If Not Intersect(Target, Range("D8")) Is Nothing ThenorCall
How to trigger run aMyMacro2
Macro by clicking a specific cell in Excel?
If Not Intersect(Target, Range("D10")) Is Nothing Then Call MyMacro3
End If
End Sub
Reply Share Read more

Matt · 6 months ago

Trigger Or Run A Macro By Clicking A Specific Cell With VBA Code, couldn't get this to work. I tried it many different way, but it never
acheived what was promised.
Reply Share

Peter · 6 months ago

This code will only work if you place it in the "ThisWorkbook" module. It does not work on a general module.
workbookname > Microsft Excel Objects > ThisWorkbook.
Reply Share

PritishS · 3 months ago

This code will work on worksheet code module. You need to right click on sheet tab and click on 'View Code'. This will open
code module for that worksheet only. Then paste the mentioned code.
Reply Share

Home (/) Knowledge (/documents.html) Support (/support.html) Forum (/forum.html) Privacy Policy (/privacy-policy.html)

About Us (/support/about-us.html)
Copyright © 2009 - 2018 ExtendOffice.com | All Rights Reserved. Sitemap (/component/jmap/sitemap.html)
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other
countries.

https://www.extendoffice.com/documents/excel/4354-excel-click-on-cell-to-run-macro.html#a1 8/8

Potrebbero piacerti anche