![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Location: London , UK
Posts: 4
|
How can i get the lowest non zero value among a set of integers within excel VBA ?
|
|
|
|
|
|
#2 | |
|
Board Regular
Join Date: Apr 2002
Location: Kissimmee, Florida
Posts: 384
|
Quote:
Code:
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
then this will do it. Code:
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
__________________
Hope This Helps. Sean. Digest of Homes WinXP, XL XP |
|
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
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
Jay |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|