Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Return Largest Value in an Array

i have an array ARRAY(10). The array contains different numbers. I would like
to return the largest number in the array to another variable LARGEST.

LARGEST = MAX(ARRAY(10))

Something like =Max(1,2,3,4,5)

Unfortunately I have not been able to determine how to use the MAX math
function to in VBA or if it can be used on an array.

Thank you for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Return Largest Value in an Array

Loop through your array

YourArray = Array(1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1)

For Each arr In YourArray
If largest < arr Then largest = arr
Next arr

hth

Carlo

PS: Maybe there is a shortcut...but at least it works.

On Nov 15, 11:52 am, Rob wrote:
i have an array ARRAY(10). The array contains different numbers. I would like
to return the largest number in the array to another variable LARGEST.

LARGEST = MAX(ARRAY(10))

Something like =Max(1,2,3,4,5)

Unfortunately I have not been able to determine how to use the MAX math
function to in VBA or if it can be used on an array.

Thank you for your help.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Return Largest Value in an Array

One shortcut would be to use Excel's =max() worksheet function:

Option Explicit
Sub testme()
Dim YourArray As Variant
YourArray = Array(1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1)
MsgBox Application.Max(YourArray)
End Sub



carlo wrote:

Loop through your array

YourArray = Array(1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1)

For Each arr In YourArray
If largest < arr Then largest = arr
Next arr

hth

Carlo

PS: Maybe there is a shortcut...but at least it works.

On Nov 15, 11:52 am, Rob wrote:
i have an array ARRAY(10). The array contains different numbers. I would like
to return the largest number in the array to another variable LARGEST.

LARGEST = MAX(ARRAY(10))

Something like =Max(1,2,3,4,5)

Unfortunately I have not been able to determine how to use the MAX math
function to in VBA or if it can be used on an array.

Thank you for your help.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Return Largest Value in an Array

Thanks works great!

"carlo" wrote:

Loop through your array

YourArray = Array(1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1)

For Each arr In YourArray
If largest < arr Then largest = arr
Next arr

hth

Carlo

PS: Maybe there is a shortcut...but at least it works.

On Nov 15, 11:52 am, Rob wrote:
i have an array ARRAY(10). The array contains different numbers. I would like
to return the largest number in the array to another variable LARGEST.

LARGEST = MAX(ARRAY(10))

Something like =Max(1,2,3,4,5)

Unfortunately I have not been able to determine how to use the MAX math
function to in VBA or if it can be used on an array.

Thank you for your help.



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
How do I search for the second largest value in the array? Golf Excel Worksheet Functions 2 April 22nd 10 09:33 AM
how to sum 'n' largest values *not* in an array? memilanuk[_2_] Excel Discussion (Misc queries) 7 May 11th 09 04:21 PM
Return 1st, 2nd, 3rd largest test values John Excel Worksheet Functions 8 March 22nd 08 04:44 PM
Reference to the N-largest value in an array [email protected] Excel Worksheet Functions 4 August 31st 07 10:13 AM
Find Largest and Return Column Name Tom321 Excel Worksheet Functions 2 March 17th 06 05:09 PM


All times are GMT +1. The time now is 04:23 PM.

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"