Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Can you identify the maximum value in an array?

Dim Arr(5) as integer

Arr(2) = 99
Arr(3) = 101

How do I then find out what the maximum value is, and what position itıs at
in this type of array * i.e. for the above, the maximum is 101, at position
3.

Iıve had success with

Application.WorksheetFunction.Large(Arr, 1)

But still canıt get the position of that number.

Iım attempting this with an array that is 1000 in size if thatıs going to
be a problem ...

Thanks,

Brad.)



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Can you identify the maximum value in an array?

Application.Match(Application.Max(Arr),Arr) or

Application.Match(Application.Large(Arr,1),Arr)

Alan Beban

Brad Patterson wrote:
Dim Arr(5) as integer

Arr(2) = 99
Arr(3) = 101

How do I then find out what the maximum value is, and what position it?s
at in this type of array ? i.e. for the above, the maximum is 101, at
position 3.

I?ve had success with

Application.WorksheetFunction.Large(Arr, 1)

But still can?t get the position of that number.

I?m attempting this with an array that is 1000 in size if that?s going
to be a problem ...

Thanks,

Brad.)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Can you identify the maximum value in an array?

Brad,
there's probably a simpler way, but you could loop through
the array testing all the values. This code works fine,
although you'll have to modify it if your highest value is
potentially below zero and if there are two or more equal
highest values it'll only identify the first, but I'm sure
you can cross that bridge when you come to it.

Sub BiggestInArray()

Dim TestArray(1000) As Integer, HighestValue As Integer,
HighestPos As Integer
HighestValue = 0

TestArray(1) = 3
TestArray(54) = 46
TestArray(897) = 24

For x = LBound(TestArray) To UBound(TestArray)

If TestArray(x) HighestValue Then
HighestValue = TestArray(x)
HighestPos = x
End If

Next x

MsgBox ("The highest value in the array is " &
HighestValue & " at position " & HighestPos & ".")

End Sub

Cheers, Pete

-----Original Message-----
Dim Arr(5) as integer

Arr(2) = 99
Arr(3) = 101

How do I then find out what the maximum value is, and

what position itıs at
Iıve had success with
Application.WorksheetFunction.Large(Arr, 1)
But still canıt get the position of that number.
Iım attempting this with an array that is 1000 in size
Thanks,

Brad.)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Can you identify the maximum value in an array?

WorksheetFunction.Match(max, arr, False)

Example
Sub test()

Dim ar(1 To 5) As Long
Dim i As Long
Dim max As Long
For i = 1 To 5
ar(i) = Int(Rnd * 1000)
Next
max = Application.WorksheetFunction.max(ar)
Debug.Print max; " @ "; _
WorksheetFunction.Match(max, ar, False)

End Sub


Patrick Molloy
Microsoft Excel MVP
-----Original Message-----
Dim Arr(5) as integer

Arr(2) = 99
Arr(3) = 101

How do I then find out what the maximum value is, and

what position itıs at
in this type of array * i.e. for the above, the maximum

is 101, at position
3.

Iıve had success with

Application.WorksheetFunction.Large(Arr, 1)

But still canıt get the position of that number.

Iım attempting this with an array that is 1000 in size

if thatıs going to
be a problem ...

Thanks,

Brad.)



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Can you identify the maximum value in an array?

Just out of educational curiosity... On an array with 1,000 numbers, I
found that using Max was a little faster than Large by about 20-30% .

--
Dana DeLouis
Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Brad Patterson" wrote in message
...
Dim Arr(5) as integer

Arr(2) = 99
Arr(3) = 101

How do I then find out what the maximum value is, and what position itıs

at
in this type of array * i.e. for the above, the maximum is 101, at

position
3.

Iıve had success with

Application.WorksheetFunction.Large(Arr, 1)

But still canıt get the position of that number.

Iım attempting this with an array that is 1000 in size if thatıs going to
be a problem ...

Thanks,

Brad.)







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array formula to Identify Leading Zeros. Commish Excel Discussion (Misc queries) 2 December 22nd 09 04:13 PM
How do identify if a number is NOT in an array? Ed Excel Discussion (Misc queries) 1 April 15th 09 04:33 PM
Finding Location of Maximum Value in 2D Array [email protected] Excel Discussion (Misc queries) 17 November 10th 06 02:36 PM
Finding Location of Maximum Value in 2D Array [email protected] Excel Worksheet Functions 15 November 9th 06 05:23 AM
Identify occurence in "array" which meets condition(s) Melissa Excel Discussion (Misc queries) 3 August 18th 05 12:59 PM


All times are GMT +1. The time now is 02:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright İ2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"