Solved

Auto Running A Macro

Posted on 2011-09-11
2
230 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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