Results 1 to 2 of 2

Thread: [RESOLVED] max and min

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Resolved [RESOLVED] max and min

    if i have vaue in celll 17.09,18,03,14,05,14.03
    i want to get min value ie 14.05
    and max value 18.03
    the below code shows min and max after deceimal point

    For i = 1 To 4
    myarray(i) = Cells(i, 1).Value
    myarray2(i) = Cells(i, 1).Value
    Next i

    MsgBox "Max = " & Application.WorksheetFunction.Max(myarray)
    Cells(1, 2).Value = Application.WorksheetFunction.Max(myarray)
    MsgBox "Min= " & WorksheetFunction.Min(myarray2)
    Cells(1, 3).Value = WorksheetFunction.Min(myarray2)
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: max and min

    this is hard to pick as your list of numbers does not contain either 14.05 or 18.03 (and 14.03 is actually the min), i presume this is some typing error

    your code works when i test it (if the numbers in list are fixed), but some of it is not really required

    vb Code:
    1. set r = range("a1:a4")
    2. MsgBox "Max = " & Application.WorksheetFunction.Max(r)
    3. Cells(1, 2).Value = Application.WorksheetFunction.Max(r)
    4. MsgBox "Min= " & WorksheetFunction.Min(r)
    5. Cells(1, 3).Value = WorksheetFunction.Min(r)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width