Results 1 to 7 of 7

how to output multiple results of a single function by running the function only once

Threaded View

luv2glyd how to output multiple... 11-14-2016, 05:46 PM
TMS Re: how to output multiple... 11-14-2016, 06:05 PM
MrShorty Re: how to output multiple... 11-14-2016, 06:34 PM
mikerickson Re: how to output multiple... 11-14-2016, 06:38 PM
luv2glyd Re: how to output multiple... 11-14-2016, 06:45 PM
MrShorty Re: how to output multiple... 11-14-2016, 06:52 PM
luv2glyd Re: how to output multiple... 11-14-2016, 07:24 PM
  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Question how to output multiple results of a single function by running the function only once

    I have a function that looks something like this:

    Function my_function(var_number As Long, a As Variant, b As Variant, c As Variant)
    
    'do some calculations here, then:
    
    'Function output:
    Select Case var_number
    
        Case 1
            my_function = output_1
        Case 2
            my_function = output_2
        Case 3
            my_function = output_3
        Case Else
            my_function = 0
        End Select
    
    End Function
    Then to run the function and get an output, I would do this: x = my_function(1, a, b, c) to get output_1, y = my_function(2, a, b, c) to get output_2, and so on. This, however, involves running the function every time I need to calculate one of the 3 outputs. I there a way to output ALL function results at ounce as a vector/array somehow, but by running the function only once instead of 3 separate times?

    The code is massive, and I need to be able to run it as efficiently as possible, so each millisecond matters. The resulting vector/array does not need to be transferred to the spreadsheet, but will only be used within the VB code.
    Last edited by luv2glyd; 11-14-2016 at 07:25 PM.
    You either quit or become really good at it. There are no other choices.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Running Multiple VBA function
    By dedark05 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-20-2016, 09:29 PM
  2. Replies: 8
    Last Post: 06-02-2016, 03:00 AM
  3. Compare values and output cell titles, able to output multiple results
    By TMG2016 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-07-2016, 11:42 AM
  4. create an inline function that will output only a certain number of results.
    By blackspiral in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-10-2013, 10:06 AM
  5. [SOLVED] Combined AND function not reading output of the function of another cell
    By Duoae in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-19-2012, 09:22 AM
  6. [SOLVED] Require Function to Lookup and Concatenate Mulltiple Results To Single Cell
    By nuttyengineer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2012, 12:19 AM
  7. User defined function to output multiple values
    By firefly2k8 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2010, 12:03 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