Find the highest number in the array

‘This code demonstrate how to find the highest number in a numaric array.
 
Dim num, i, Length1

num=array(34,12,98,43,89,49,56)
Length1 = UBound(num)    ‘Find the length of array

For i= 1 to Length1
 If (num(i) < num(0)) Then  ‘to find lowest number, just change it to >
    num(0)=num(i)
 End If
Next

MsgBox num(0) ‘Highest Number

10 thoughts on “Find the highest number in the array”

  1. i tried to pass numbers(5,10,15) in array to find the biggest number and getting as 5. but it should be 15. pls help me in this.

    num=array("5","10","15")
    Length1 = UBound(num)
    For i= 1 to Length1
    If (num(i)>num(0)) Then
    num(0)=num(i)
    End If
    Next

    MsgBox num(0)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top