Results 1 to 5 of 5

How do I pass a built array back to formula

Threaded View

  1. #1
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Smile How do I pass a built array back to formula

    I’m trying to send an array of values INTO a user defined function, do a little math on it, and then send the resulting array back to the caller. The caller in this case is an array formula in an excel cell. I can get it to build an array after the math, but I can’t get it to pass the resulting array back to the formula. The following snippet is a simple version of the code. Here I am building the incoming array in the macro, but same difference at the end. The outgoing Oil_spgr variable never seems to contain the full, final array.

    Function Oil_spgr()
    Dim Spgr_Result() As Variant
    ReDim Spgr_Result(1 To 4)
    Temp = 480
    For i = 1 To 4
      ' Oil_spgr(i) = -0.0002265 * Temp + 0.886023 … most direct method of storing new array
      Spgr_Result(i) = -0.0002265 * Temp + 0.886023
      Oil_spgr(i) = Spgr_Result(i) ' … store new array after building phantom array, the phantom array builds-up ok, but Oil_spgr won’t
      Temp = Temp + 10
    Next i
    End Function
    Last edited by sauerj; 11-13-2009 at 02:07 PM. Reason: Added CODE TAGS properly ...

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