|
-
Nov 27th, 2009, 01:43 PM
#1
Thread Starter
Addicted Member
[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
-
Nov 27th, 2009, 03:20 PM
#2
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:
set r = range("a1:a4") MsgBox "Max = " & Application.WorksheetFunction.Max(r) Cells(1, 2).Value = Application.WorksheetFunction.Max(r) MsgBox "Min= " & WorksheetFunction.Min(r) 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|