Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default sort numeric array

hi! I have an array with numbers. i want to sort the array based on the size
of the numers. how can i do this? do I need to write a function for it or
does it exist in vba already? please help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default sort numeric array

Arne,
One of these methods in VBA, depending on the number of elements:
http://www.google.co.uk/search?hl=en...G=Search&meta=

Or get Excel to do the sort for you:
Dump the array on a WS, out of the way
Sort on the WS
Pick up the sorted values.

NickHK

"Arne Hegefors" wrote in message
...
hi! I have an array with numbers. i want to sort the array based on the

size
of the numers. how can i do this? do I need to write a function for it or
does it exist in vba already? please help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default sort numeric array

here's an example, don't remember who posted it, though:

Sub sort_array()
Dim arr As Variant
Dim i As Long, j As Long, temp As Long
'sort the array
arr = Array(2, 3, 4, 1, 6, 8, 7)
For i = LBound(arr) To UBound(arr) - 1
For j = i + 1 To UBound(arr)
If arr(i) arr(j) Then
temp = arr(j)
arr(j) = arr(i)
arr(i) = temp
End If
Next j
Next i
MsgBox arr(0)
End Sub

--


Gary


"Arne Hegefors" wrote in message
...
hi! I have an array with numbers. i want to sort the array based on the size
of the numers. how can i do this? do I need to write a function for it or
does it exist in vba already? please 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
Updating workbook with an alpha sort sheet and a numeric sort shee cjlatta Excel Discussion (Misc queries) 2 January 28th 09 12:00 AM
can you sort numeric address numbers by even/odd FireBrick New Users to Excel 2 March 7th 07 03:47 AM
Alpha Numeric Sort Cptn_Jon Excel Discussion (Misc queries) 1 December 1st 06 04:14 PM
Sort a numeric field sdmccabe Excel Discussion (Misc queries) 5 June 28th 05 08:54 AM
sort multi-dimensional array on numeric data? RB Smissaert Excel Programming 0 July 14th 03 10:49 PM


All times are GMT +1. The time now is 02:22 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"