Rufus Clupea
Board Regular
- Joined
- Feb 11, 2019
- Messages
- 85
I'm sure this has come up before (multiple times), and I did search via google (as recommended) but all I could find was functions that would determine Max/Min from a Range of Cells, and that's not what I need. If someone could even point me to a pertinent thread, that'd be great (but please read on ).
I wrote a couple of simple Functions for returning the Greater of/Lesser of 2 numbers:
I realize they're not particularly "elegant" , but they get the job done (I don't need to know which is greater/less; I just need the value). What I need now is a couple of similar functions that will return the Greater of/Lesser of a short list (up to 5) of Integers, but with more than 2 arguments being optional(?), and not involving/referencing a Worksheet Range (just passing them as arguments).
I spoze something like:
would work (using 0s for some of the arguments), but I'm at a bit of a loss as to what goes in-between Function and End Function other than a rather large group of If-Thens or a Select Case. Again, I'm thinking this has come up before—I just can't FIND it.
A single dual-purpose function passing Max or Min as the initial argument would also be fine, e.g:
Again, all I need returned is the single Value.
TIA
I wrote a couple of simple Functions for returning the Greater of/Lesser of 2 numbers:
Code:
' RETURNS GREATER OF 2 NUMBERS
Function GreaterOf(x As Long, y As Long)
If x > y Then GreaterOf = x Else GreaterOf = y
End Function 'GreaterOf(x, y)
' RETURNS LESSER OF 2 NUMBERS
Function LesserOf(x As Long, y As Long)
If x < y Then LesserOf = x Else LesserOf = y
End Function 'LesserOf(x, y)
I realize they're not particularly "elegant" , but they get the job done (I don't need to know which is greater/less; I just need the value). What I need now is a couple of similar functions that will return the Greater of/Lesser of a short list (up to 5) of Integers, but with more than 2 arguments being optional(?), and not involving/referencing a Worksheet Range (just passing them as arguments).
I spoze something like:
Code:
Function GreatestOf(a As Long, b As Long, c As Long, d As Long, e As Long)
End Function
would work (using 0s for some of the arguments), but I'm at a bit of a loss as to what goes in-between Function and End Function other than a rather large group of If-Thens or a Select Case. Again, I'm thinking this has come up before—I just can't FIND it.
A single dual-purpose function passing Max or Min as the initial argument would also be fine, e.g:
Code:
Function Max_Min_Of(MaxMin As String, a As Long, b As Long, [c As Long], [d As Long], [e As Long])
End Function
Again, all I need returned is the single Value.
TIA