Return Multiple Values from a Visual Basic Function
A normal VBA function has a return statement that returns a value to the calling function/subroutine
If you want multiple values to be returned, use reference parameters. The reference parameter represents the same storage location as the argument variable and hence changes made in the function is reflected in the calling function too.
Sub ReturnMultipleValue()
Dim L As Double
Dim B As Double
L = 10
B = 6
Debug.Print L & " " & B
ChangeLengthAndBreadth L, B
Debug.Print L & " " & B
End Sub
The above sub passes the arguments to ChangeLengthAndBreadth function by reference. That is, the storage location is passed to function and the changes made inside the ChangeLengthAndBreadth function is reflected in the main method.
Function ChangeLengthAndBreadth(ByRef Length As Double, ByRef Width As Double)
Length = 1.2 * Length
Width = 1.2 * Width
End Function
Multiple Return Parameters in VBA, Multiple Return Parameters in Visual Basic, Return Multiple Values – VBA Function, VBA Function to return more than one value
See also:
Output Parameters in C# (.NET)
How to get the return value from C# program (console application)