Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Auto Running A Macro

Posted on 2011-09-11
2
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Norie earned 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

730 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