+ Reply to Thread
Results 1 to 5 of 5

Function that returns multiple values?

  1. #1
    Registered User
    Join Date
    02-27-2008
    Location
    Irving, Texas
    MS-Off Ver
    MS Office 2016
    Posts
    96

    Function that returns multiple values?

    Hi all,

    I've never quite mastered the idea of passing arguments between subs and functions. I have a project right now where I am writing this same bit of code over and over, for different parts of the macro:
    Please Login or Register  to view this content.
    It basically checks each sheet in the current workbook to see if any have the name specified, in order to avoid duplicating sheets. I think I can write this as a function that would take as an argument the desired name and would return TRUE/FALSE if that sheet existed, and an integer representing the sheet # for that sheet. However, I can't figure out how to get a function to return multiple values. I tried the code below, based on some Microsoft examples, but it doesn't work because I don't know how to call the function with the intent of using one or both of its outputs:
    Please Login or Register  to view this content.
    Can someone point me in the direction of a good, beginner's guide to functions w/ multiple outputs?
    Last edited by ahartman; 10-14-2009 at 10:44 AM. Reason: solved
    -Adam Hartman
    Mechanical Engineer

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Function that returns multiple values?

    Try this. Select two adjacent cells (e.g. A1 and B1) and enter the formula with Ctrl+Shift+Enter as it is an array formula.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-27-2008
    Location
    Irving, Texas
    MS-Off Ver
    MS Office 2016
    Posts
    96

    Re: Function that returns multiple values?

    Quote Originally Posted by StephenR View Post
    Try this. Select two adjacent cells (e.g. A1 and B1) and enter the formula with Ctrl+Shift+Enter as it is an array formula.
    Please Login or Register  to view this content.
    So maybe I don't even want it to be a function? I want to use the returned values in the macro, not in any cells. I want to be able to just include a line in my macro code that says bCheckSheets(sCurrentLog) that returns TRUE/FALSE and the sheet #.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Function that returns multiple values?

    You're not really explaining what you want to do, but it appears that the individual elements of the array formula can be referenced.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-27-2008
    Location
    Irving, Texas
    MS-Off Ver
    MS Office 2016
    Posts
    96

    Re: Function that returns multiple values?

    StephenR,

    Sorry if my explanations have been unclear. I think the key piece of info I was missing is included in your code:
    Please Login or Register  to view this content.
    I didn't know that syntax. Thanks for the help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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