PDA

View Full Version : I like to find next small value..



juneve77
05-21-2018, 04:12 PM
How can I find next small value and on and on..
If there is more than one same small value how can I go to next one?


small = Application.WorksheetFunction.Min(rng)
srow = Application.WorksheetFunction.Match(small, rng, 0)

Cells(srow, "p").Select


please help me~~

p45cal
05-22-2018, 04:43 PM
Check out range.find in excel's vba Help.
There's a snippet of code like:
With Worksheets(1).Range("a1:a500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
adapt it along the lines of:
With Rng
Small = Application.WorksheetFunction.Min(Rng)
Set c = .Find(Small, LookIn:=xlValues, lookat:=xlWhole, searchformat:=False)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Select
MsgBox "Note selected cell"
Set c = .FindNext(c) 'for FindNext to work properly, rng should be one contiguous block of cells.
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With

p45cal
05-22-2018, 04:53 PM
I see you've cross posted this question elsewhere, please supply link(s) to those crossposts here.
Have a read of http://www.excelguru.ca/content.php?184