Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Another approach is to dimension your function as a Boolean, but pass a
bunch of arguments by ref. These might be empty placeholders passed in, but the function gives them values. If the function does its calculations correctly, without error, it returns a value of True, so the calling sub knows it can rely on the arguments passed back. These can only be used by other VBA procedures, not in UDFs. An overly simple example might go like this: Sub DumbSub() Dim i1 As Integer, i2 As Integer Dim iMin As Integer, iMax As Integer Dim bTest As Boolean Set rng = ActiveSheet.Range("A1:A10") i1 = 1 i2 = 5 bTest = GetMinMax(i1, i2, iMin, iMax) If bTest Then MsgBox iMax & " " & iMin Else MsgBox i1 & " = " & i2 End If End Sub Function GetMinMax(iOne As Integer, iTwo As Integer, _ iLow As Integer, iHigh As Integer) As Boolean If iOne = iTwo Then GetMinMax = False Exit Function End If If iOne iTwo then iHigh = iOne iLow = iTwo Else iHigh = iTwo iLow = iOne End If GetMinMax = True End Function The calling sub passes in two values to find out which is greater. It checks for an error (i.e., the two values are equal). If there's an error, it displays one message, but if there's no error, it displays a different message. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ "David Adamson" wrote in message ... thanks "agarwaldvk" wrote in message ... David You cannot return more than one variable from a function. What you can do though is return a variant containing an array. This array can contain any number of values that you might want to retun. Remember, a variant can contain any data type and that includes an array of variants as well. Hope that helps! Best regards Deepak Agarwal -- agarwaldvk ------------------------------------------------------------------------ agarwaldvk's Profile: http://www.excelforum.com/member.php...o&userid=11345 View this thread: http://www.excelforum.com/showthread...hreadid=486118 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Multiple variables to sort and sum, return values<0 with sum refer | Excel Worksheet Functions | |||
Lookup function for two variables and return another cell? | Excel Worksheet Functions | |||
using =IF function with 12 variables | Excel Discussion (Misc queries) | |||
Lookup based on two variables and return a third | Excel Worksheet Functions | |||
2 Conditions True, Many Variables, Return Result | Excel Worksheet Functions |