select max of Value in several controls

G

Greg Green

I'd like one text box to display which of a range of other text boxes has
the highest value. How would I do this? Is this a valid / simple solution:

place the Values of the boxes in an array and then use a Max(Element1,
Element2, Element3) function?

Thanks in advance
 
A

Allen Browne

Copy the function below into a module.

You can then use:
Largest(Element1, Element2, Element3)
using any number of fields.


Function Largest(ParamArray varValues()) As Variant
Dim i As Integer 'Loop controller.
Dim varMax As Variant 'Largest value found so far.

varMax = Null 'Initialize to null

For i = LBound(varValues) To UBound(varValues)
If IsNumeric(varValues(i)) Then
If varMax >= varValues(i) Then
'do nothing
Else
varMax = varValues(i)
End If
End If
Next

Largest = varMax
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top