Consulting

Results 1 to 3 of 3

Thread: I like to find next small value..

  1. #1

    I like to find next small value..

    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~~

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    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
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •