On 2002-05-20 09:25, raj wrote:
How can i get the lowest non zero value among a set of integers within excel VBA ?
Sub FindLowest()
IamTheLowest = 9E+50
LowAddr = ""
For Each c In Selection.Cells
cv = c.Value
ca = c.Address
If cv < IamTheLowest And cv <> 0 Then
IamTheLowest = cv
LowAddr = ca
End If
Next
MsgBox "Lowest Value is: " & IamTheLowest & Chr(10) & "In cell address: " & LowAddr
End Sub
Sub FindLowest()
IamTheLowest = 9E+50
LowAddr = ""
For Each c In Selection.Cells
cv = c.Value
ca = c.Address
If cv < IamTheLowest And cv > 0 Then
IamTheLowest = cv
LowAddr = ca
End If
Next
MsgBox "Lowest Value is: " & IamTheLowest & Chr(10) & "In cell address: " & LowAddr
End Sub
Sub test()
Dim x, Rng1
Set Rng1 = Range("A1:A100")
x = WorksheetFunction.Min(Rng1)
If x = 0 Then
x = Evaluate("=MIN(IF(" _
& Rng1.Address & ">0," _
& Rng1.Address & "))")
End If
MsgBox x
End Sub
Another option...
Code:Sub test() Dim x, Rng1 Set Rng1 = Range("A1:A100") x = WorksheetFunction.Min(Rng1) If x = 0 Then x = Evaluate("=MIN(IF(" _ & Rng1.Address & ">0," _ & Rng1.Address & "))") End If MsgBox x End Sub
Bye,
Jay
Sub Test()
MsgBox Evaluate("MIN(" & Replace(Application.Trim(Replace(" " & Join(Evaluate("TRANSPOSE(A1:A100)")) & " ", " 0 ", " ")), " ", ",") & ")")
End Sub
For typed characters, yes but for processes/time no.Or even shorter
Sub Test5()
MsgBox = Evaluate("minifs(a1:a100,a1:a100,""<>0"")")
End Sub
Rich (BB code):Sub Test() MsgBox Evaluate("MIN(" & Replace(Application.Trim(Replace(" " & Join(Evaluate("TRANSPOSE(A1:A100)")) & " ", " 0 ", " ")), " ", ",") & ")") End Sub
You have responded to an 18 year old thread. No matter, how about a one-liner...
MINIFS ? It looks like I am going to have to upgrade my version of Excel (eventually)... too many new functions have been introduced since XL2010.