+ Reply to Thread
Results 1 to 2 of 2

Passing Variables

  1. #1
    Jeff
    Guest

    Passing Variables

    Sorry to keep asking questions about passing variables, but here is another
    one hope you can help.

    I have a macro that received one set of values so I call it
    Macro1(X), where X is the value that is received. But Macro1(X) calculates
    about 20 other variables Y,Z,A,.... using the value X. If I call Macro1(X)
    and I need one of the variables how do I get it, do I have to declare global
    variables.

    Thanks

  2. #2
    Chip Pearson
    Guest

    Re: Passing Variables

    First of all, ensure that you have Option Explicit as the very
    first line in the code module (before and outside of any
    procedure). This will force you to declare all your variable
    rather than have VBA automatically allocate variable at run time.
    Then read up on "scope" in the VBA Help file.

    If you declare (Dim) the variable within Macro1, that variable is
    accessible only within Macro1. When Macro1 exits, the variable is
    destroyed. If you need to use calculated variables in more than
    one procedure, declare them as Public outside of and before any
    procedure.


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com



    "Jeff" <Jeff@discussions.microsoft.com> wrote in message
    news:EC421211-180F-49BE-96EB-8F4557386E56@microsoft.com...
    > Sorry to keep asking questions about passing variables, but
    > here is another
    > one hope you can help.
    >
    > I have a macro that received one set of values so I call it
    > Macro1(X), where X is the value that is received. But
    > Macro1(X) calculates
    > about 20 other variables Y,Z,A,.... using the value X. If I
    > call Macro1(X)
    > and I need one of the variables how do I get it, do I have to
    > declare global
    > variables.
    >
    > Thanks




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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