ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to find the maximum from a list of variables? (https://www.excelbanter.com/excel-programming/378565-re-how-find-maximum-list-variables.html)

Chip Pearson

How to find the maximum from a list of variables?
 
Kyrsten,

Try a function like the following:

Function MaxOfVariables(ParamArray V()) As Variant
Dim N As Long
Dim Max As Double
If IsMissing(V) = True Then
MaxOfVariables = CVErr(xlErrValue)
Exit Function
End If
For N = LBound(V) To UBound(V)
If IsNumeric(V(N)) Then
If CDbl(V(N)) Max Then
Max = CDbl(V(N))
End If
Else
MaxOfVariables = CVErr(xlErrNum)
Exit Function
End If
Next N
MaxOfVariables = Max
End Function

If no variables as passed to it, it will cause a #VALUE error. If any
variable is not numeric, it returns a #NUM! error. If everything is numeric,
it will return the maximum of the values passed in.

Dim MyMax As Double
MyMax = MaxOfVariables(a,b,c,d)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"KyWilde" wrote in message
...
I have a list of four varables: a, b, c, d all have integer values...

I would like to figure out the maximum amount from the four. How can I do
this? Is there a max(a,b,c,d) function I can use? Or do I need to write
one?

Thanks,
-Kyrsten Wilde





All times are GMT +1. The time now is 10:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com