+ Reply to Thread
Results 1 to 7 of 7

Calling multiple values from a function within a code

  1. #1
    Forum Contributor
    Join Date
    10-01-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    125

    Calling multiple values from a function within a code

    Hi,

    I am writing a macro (main macro). In which I am calling a function having multiple calculations with multiple variables. It is doing all perfect in the function but not returning all these variables in the main macro after this function ends. How can I connect my main macro with these sub functions to get all the output from these functions in the main macro. I don't have any idea.

    Can any body help ,me on this?
    Last edited by krish T; 11-11-2010 at 01:06 PM. Reason: solved

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Calling multiple values from a function within a code

    That's very vague. Can you post your code, and detail your intended results?

  3. #3
    Forum Contributor
    Join Date
    10-01-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    125

    Re: Calling multiple values from a function within a code

    Hi

    Attached the example sheet. I have given simple example for my understanding purpose. Please look at the code and suggest me how to pass the variables from main code to the sub functions and call variables from sub function to the main code.

    Thanks for your help.
    Attached Files Attached Files

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Calling multiple values from a function within a code

    Main code:
    Please Login or Register  to view this content.
    Called code:
    Please Login or Register  to view this content.
    Note: I changed the name of your array variable as Dir is a VBA function.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Contributor
    Join Date
    10-01-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    125

    Re: Calling multiple values from a function within a code

    Working perfect. Thanks. But small doubt. When I deleted "As String" from the below line in the called code
    Please Login or Register  to view this content.
    , it is giving problem in the main code. If that is the case, Do I have define count As Long, stat As String, Time As String in the called code or do I have to define type for all the variables in the called code. Thanks for your help.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Calling multiple values from a function within a code

    Your variable types should match. Since you haven't declared any of the other variables, they are Variants, and therefore they match the sub's declaration. The array argument is declared as an array, therefore if you remove the As String, you are declaring it as an array of Variants (not as a Variant - the two are different), but trying to pass an array of Strings.
    It is best to specifically type all the arguments where possible.

  7. #7
    Forum Contributor
    Join Date
    10-01-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    125

    Re: Calling multiple values from a function within a code

    Thanks to all of your help.

    krish

+ 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