+ Reply to Thread
Results 1 to 9 of 9

Need my Value to Continue to Another Called Macro

  1. #1
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Need my Value to Continue to Another Called Macro

    Please see example below:

    Please Login or Register  to view this content.
    What I would like is for myvalue to continue equaling what it equaled in Macro1 into Macro2. This is just an example, in my actual sheet I will have about 20 different values that need to continue into the next macro.

    Thanks,

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Need my Value to Continue to Another Called Macro

    Maybe declare myValue as a shared private variable?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: Need my Value to Continue to Another Called Macro

    Hi JieJenn,

    This works great thanks, but I've got one more problem. This seems to only work when both macros are in the one module. Is there any way of getting the same result with macro1 being in module 1 and macro2 being in module 2? Sorry, I should have been more specific in my first post.

    Thanks again.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,529

    Re: Need my Value to Continue to Another Called Macro

    Try:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: Need my Value to Continue to Another Called Macro

    Excellent TMS. Works perfectly.

    Thanks TMS and JieJenn for your help.

  6. #6
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: Need my Value to Continue to Another Called Macro

    Sorry, another question. Does this now mean every variable that's part of the macro has to be defined? If I'm using x as part of a loop, but do not need to have x's value continue to the next macro, I'll still need to define it? I seem to be getting a compiler error. I have not worked with defining variable that much, so it's a bit confusing, I'm use to just typing x = 1, and nothing more.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,529

    Re: Need my Value to Continue to Another Called Macro

    You're welcome. Thanks for the rep.


    Defining (Dimming/Dimensioning) your variables is good practice and mandatory if you use Option Explicit.

    Option Explicit helps to avoid mistakes where, say one variable is incremented and another is tested - maybe x1 and x2.

    If you really don't want to Dim your variables, remove the Option Explicit ... but you would be better off getting into the habit of defining them appropriately.

    Regards, TMS

  8. #8
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: Need my Value to Continue to Another Called Macro

    Sorry, what I should be saying is. Is there a way around not declaring variables, unless the next macro requires that variable. Not sure if this will make sense. Please see my attachment.

    Thanks.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: Need my Value to Continue to Another Called Macro

    Ignore post 8. Posted that when you had replied. What you have mentioned in post 7 works great. Slowly learning the variable side of things, but don't have a good understanding, so I'm leaving them out when possible for the time being, until I understand it a bit better.

    Thanks again, much appreciated.

+ 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. Pause Macro, move to another cell, continue macro execution
    By slotcardan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-04-2014, 08:23 PM
  2. Replies: 0
    Last Post: 03-28-2013, 10:25 AM
  3. Replies: 2
    Last Post: 02-24-2011, 05:17 PM
  4. Exiting called macro on error, then ending macro caller.
    By Yappa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2008, 10:28 PM
  5. Replies: 3
    Last Post: 07-06-2006, 02:45 PM

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