View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jason Sharp[_2_] Jason Sharp[_2_] is offline
external usenet poster
 
Posts: 2
Default Rank items in VBA Array?

hi dude. I've never used the Array method before, but maybe I can help. It's
apparent that your desired list return is an algo for the first "digit" in
each number of the assigned element. Additionally, I see no logical
sequential pattern occurring. Finally, I have never used the Rank function
before, I'm assuming that you wrote a function with assigned parameters. That
said...

Are you sure your LOOP CODE is correct? You wrote "For i = 1 To
UBound(Myarray1)". Check the info on the Array method, your counter might
start at 0 not 1. A working procedure that returns the wrong information in
this circumstance would return 4, 5, 1, 3 [w/o the 2]. Traditionally variable
arrays begin with an element 0.

"jasonsweeney" wrote:


I have a VBA array of large numbers. I need to rank the items within
the array and drop them (in order) into a textbox. For example:

Input: Array(27, 43, 51, 14, 33)
Output in textbox should be: 2, 4, 5, 1, 3 (delimited here with
commas for informational purposes only. Actual output would be
"24513")

I would hope this would be simple in VBA, but looking at the posts
regarding ranking and sorting arrays, it looks more difficult than I
thought. And no, I don't want to put the data onto the worksheet and
rank it there. VBA code only please.

Here is the code I tried which does not work:
________________________________________
Private Sub CommandButton1_Click()
Myarray1 = Array(27, 43, 51, 14, 33)
For i = 1 To UBound(Myarray1)
Rank_num = Application.WorksheetFunction.Rank(Myarray1(i),
Myarray1, 0)
UserForm1.TextBox1.Value = UserForm1.TextBox1.Value & Rank_num
Next
End Sub
________________________________________

Suggestions appreciated.


--
jasonsweeney
------------------------------------------------------------------------
jasonsweeney's Profile: http://www.excelforum.com/member.php...fo&userid=5222
View this thread: http://www.excelforum.com/showthread...hreadid=475286