Solved

Auto Running A Macro

Posted on 2011-09-11
2
216 Views
Last Modified: 2012-05-12

EE Pros,

Simple related question;

If I have a macro called "Run_Order" that right now appears as a button with an associated Macro.    I want it to run automatically, each time it sees a change or entry to a particular column of cells, what is the simple code I use and do I put it in "ThisWorkbook" or the Sheet or a Module?  The macro only partains to a particular sheet and only when the sheet is open.

Thank you,

B.
0
Comment
Question by:Bright01
2 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 36519183
Right click the tab of the sheet you want it to work with.

Then select Change from the right drowdown above the code window.

You should now see this, which is where the code should go.
Private Sub Worksheet_Change(ByVal Target As Range)

End Sub

Open in new window

To check if the change was made in a specific column there are various ways, here's one.
Dim rng As Range 

      Set rng = Range("A:A") ' range to check for change

      If Intersect(rng, Target) Is Nothing Then Exit Sub ' if change not in range then exit the code

      Application.EnableEvents = False

      Call Run_Order        ' call the code you want to run

      Application.EnableEvents = True

Open in new window

This is the basic idea, and will only work for the range you specify on the worksheet the code is in when the workbook is open.
       
0
 

Author Closing Comment

by:Bright01
ID: 36519425
Thank you!  Works perfectly.

B.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question