+ Reply to Thread
Results 1 to 8 of 8

Sub routines knowing which Sub called.

  1. #1
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    180

    Sub routines knowing which Sub called.

    I have 3 subroutines Check, Submit and Filter. Check and Submit both call on Filter to Filter on a given spreadsheet. I want to have an If Statement in the Filter Macro that allows me to forego a MsgBox if the Macro detects the data is clean if Submit is run, but want to execute the MsgBox if Check is run. Is there some VBA language that will do that or should I designate a range on a spreadsheet to 0 and 1 it based on the Macro that called?

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

    Re: Sub routines knowing which Sub called.

    you can use an arguement in Filter

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Sub routines knowing which Sub called.

    Thank you Andy, that worked. If I wanted to keep other variables such as this:
    Please Login or Register  to view this content.
    Is there a way to keep that as well?

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

    Re: Sub routines knowing which Sub called.

    Sorry I don't understand the question

  5. #5
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Sub routines knowing which Sub called.

    Is there a way to keep the Dims I created in Sub1 in Sub2 if I call on Sub2 from Sub1?

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

    Re: Sub routines knowing which Sub called.

    well you could pass as arguments or declare at the module level, rather than routine level, which would expand their scope. Code is normally cleaner though if you limit scope.

  7. #7
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Sub routines knowing which Sub called.

    I know this might sound like a dumb question, but why is that?

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

    Re: Sub routines knowing which Sub called.

    This explains the meaning of scope
    http://support.microsoft.com/kb/141693

    The main reason is,
    "Keep the scope of variables as small as possible to avoid confusion and to ensure maintainability. Also, when maintaining legacy source code, the potential for inadvertently breaking other parts of the code can be minimized if variable scope is limited."

    Source: http://msdn.microsoft.com/en-us/libr...x#cfr_bestprac

+ 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. Replies: 0
    Last Post: 02-21-2013, 08:28 AM
  2. Help with Calling Routines
    By HappyHole in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-07-2011, 04:08 AM
  3. DateSeriial in Sub Routines
    By GogsJames in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-24-2006, 07:04 AM
  4. [SOLVED] Calling sub routines
    By Andrew in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2005, 12:05 PM
  5. [SOLVED] vb dummy - two routines
    By Greg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-20-2005, 12:05 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