+ Reply to Thread
Results 1 to 15 of 15

Run Macro when Workbook changes

  1. #1
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    Run Macro when Workbook changes

    Hi guys,

    I need a macro that should run other macros when something changes in Workbook ("Input"). Range (B6:EU37).
    However, the macro should not be a Private Sub.

    Is this possible!? if yes, I really appreciate your help!

    Thanks

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Run Macro when Workbook changes

    The macro code does not need to be private.

    The event code might be though. Can the range B6:EU37 be on any sheet in the Workbook Input?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Run Macro when Workbook changes

    Hi,

    thanks for your reply.
    Sorry, I meant Worksheet, not Workbook.
    So, when changes occur in Worksheet ("Input") within the specified range, the macro should call Macro_2 for example...

    Cheers

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Run Macro when Workbook changes

    So right click sheet tab and View Code.

    Please Login or Register  to view this content.
    Macro_2 code can be in a standard code module.

  5. #5
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Run Macro when Workbook changes

    Thanks!

    Sadly it does not work. I guess because of the Option Explicit on the top, which I need for further macros in the code.
    That's why I thought it must be the Private Sub that does not go with the Option Explicit.

    Please see my code below. When trying to run the code, the private sub does not appear in the dialog box and therefore cannot be run.

    Please Login or Register  to view this content.
    cheers

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Run Macro when Workbook changes

    Nothing to do with option explicit.

    If you placed Macro_2 in the worksheet object (same place as the event code) then it should appear in the Macro dialog as Input.Macro_2

    But as I said you can place Macro_2's code in a standard code module.

  7. #7
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Run Macro when Workbook changes

    I took 1:1 the code you provided me with.

    Should I have done something more? If yes could you please enter the changes in the code you gave me?

    Right now, I do changes in Worksheet ("Input"), without that the macro calls macro_2 and runs the rest of the code.

    As mentioned, the dialog box does not list the private sub in the macros list...please see attachment
    Attached Images Attached Images

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Run Macro when Workbook changes

    Can not really tell from screen shot.

    In the attached example Macro_2 code is in a standard code module, which is separate from Input sheet code.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Run Macro when Workbook changes

    Obviously I am doing something wrong, because it does not seem to work...

    In the attached Excel File you can see the entire code and macros.
    As mentioned before, I need that the code is being run starting with macro_2 whenever I do changes in Sheet "Input"...

    Please have a look, thanks!
    Attached Files Attached Files
    Last edited by vio.coman; 05-02-2014 at 07:33 AM.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Run Macro when Workbook changes

    You now have the event code in a standard module.

    Move this code from Modul1 to Input sheet code module.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Run Macro when Workbook changes

    Unfortunately I do not know how to do that....my VBA knowledge is rather poor, but thanks again!

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Run Macro when Workbook changes

    I told you how to do it in post #4.

    So first select and cut the code.
    Go to the workbook and right click the Input sheet tab. Select 'View Code'.
    Paste code.

  13. #13
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Run Macro when Workbook changes

    I worked like a charm. Many thanks!

    One more short question: is there a way to prevent the macro from shifting the view of the user from the Sheet "Input" to Sheet "Daten" every time I change something in Sheet "Input"???

    In this particular case, it would be great if the user would be able to stay in Sheet "Input" and continue changing things. Otherwise, one has to return to Sheet "Input" after each change made...

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Run Macro when Workbook changes

    Simplest way, without affecting how you existing code runs.

    Please Login or Register  to view this content.
    Add line to active sheet when you other code has finished.

  15. #15
    Forum Contributor
    Join Date
    04-03-2014
    Location
    Berlin
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Run Macro when Workbook changes

    Thanks a million! Worked out perfectly!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to find data in source workbook and copy paste to target workbook
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-23-2014, 06:21 AM
  2. [SOLVED] Save the split the workbook file type as Excel Binary Workbook From Run Macro
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-25-2013, 05:09 AM
  3. Replies: 0
    Last Post: 01-07-2013, 01:22 PM
  4. Replies: 0
    Last Post: 07-27-2011, 09:48 PM
  5. Replies: 9
    Last Post: 07-25-2005, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1