Choose The Minimal Value

alwazeer

Registered User.
Local time
Today, 14:10
Joined
Nov 9, 2011
Messages
36
Hi All

I have three numbers, and I want the program to choose the minimal value "between the three" .. with exclusion of "zero" value if it one of them ..

"If there is 1 zero of the three values, choose the minimal value from the other 2 values .. If there is 2 zero values of the three, choose the value that is"not zero" as the minimal value"

The one that remains
 

Attachments

Public Function Minimal(ParamArray p() As Variant) As Variant

Dim varReturn As Variant
Dim intCounter As Integer
varReturn = p(0)
If VarType(varReturn) = vbString Then
varReturn = "ZZZZZZZZ"
Else
varReturn = 9999999999
End If

For intCounter = 0 To UBound(p)
If p(intCounter) < varReturn And p(intCounter) & "" <> "0" Then varReturn = p(intCounter)
Next intCounter

Minimal = varReturn
End Function
 
Last edited:
Excellent work arnelgp
But how can i use the code to show the name of the shop that had minimal price ??
shop1, shop2, shop3

Thanks
 
Your database is improperly structured. When you start numerating field names (e.g. Pr1, Pr2, etc.), its time for a new table for that data. The Pr values need to be in a new table and with that you can run a simple query to get what you want using the MIN function(http://www.w3schools.com/sql/sql_func_min.asp).
 

Users who are viewing this thread

Back
Top Bottom