UDF to return to Values

clive2002

Registered User.
Local time
Today, 23:47
Joined
Apr 21, 2002
Messages
90
I have a UDF which i calculates two values.

how can i get it to return the 2 results when called.

the function takes alot of processing to run so i don't want to call it twice.
 
If you are calling it from another bit of VBA then you could define the function as an array. Returning it into an array, running it only once....

Regards
 
I am calling from VBA, how would i do this though.
 
Clive,

You can define your function as a Variant or as a user-defined
type. Either can return multiple values.

Wayne
 
Clive,

Not fancy, but ...

Code:
Private Type fReturns ' Put this in a module or on form
    Value1 As Long
    Value2 As Long
End Type


Private Sub txtVarType_Click() ' Call the function
  Dim Temp As fReturns
  Dim T As Long
  Temp = fTest()
  T = Temp.Value1
  T = Temp.Value2
End Sub

Private Function fTest() As fReturns
  fTest.Value1 = 6
  fTest.Value2 = 9
End Function

Wayne
 

Users who are viewing this thread

Back
Top Bottom