LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Ranking without preset Excel function.

i=1 -- array2(1) = 3 (occurrences of "2"),
i=2 -- array2(2) = 2 (occurrences of "4"),
i=3 -- array2(3) = 2 (occurrences of "3").


Hi. One idea is to use a Dictionary Object. Here is a general idea.
I understand you only want an array of those items with a count 1.

Sub Demo_Tally()
Dim d
Dim p
Dim n, k
Dim v
v = Array(1, 2, 4, 6, 5, 4, 7, 2, 3, 2, 3)

Set d = CreateObject("Scripting.Dictionary")
' Add Key, Item (Both Required)

'// Tally items
For p = LBound(v) To UBound(v)
n = v(p)
If d.exists(n) Then
d(n) = d(n) + 1
Else
d.Add n, 1
End If
Next p

'// Remove items with Count = 1
For Each k In d.keys
If d(k) = 1 Then d.Remove (k)
Next k

'// Display items
For Each k In d.keys
Debug.Print k, d(k)
Next k
End Sub


Returns:
Item | Count
2 3
4 2
3 2

--
HTH :)
Dana DeLouis
Windows XP & Excel 2007


"a.riva@UCL" wrote in message
ups.com...
Thanks for all the suggestions!

The code that Dana sent is working very well, and it's really
simple :-)

Now I have an other question...

I have my usual option-based-1 array1 in VBA, which contains x
numbers. Some of them are repeated. What I would like to do is
creating an other option-based-1 array, let's call it array2, which
contains the numbers of occurrences of each of the repeated elements
of array1 within array1... I'm struggling to find a solution...

For example:

option-based-1 array1 is (1, 2, 4, 6, 5, 4, 7, 2, 3, 2, 3) -- I
cannot sort the array.

I think that the procedure should do the following operation: it
detects how many items are repeated in "array1", and for each of this
repeated items stores in a new array "array2" a number corresponding
to the number of its occurrences.

For example, in array1 the procedure detects that there are n=3 items
which occur more than once (they are "2", "4" and "3"). Then it ReDims
array2 (1 to n), and for i=1 to n it gives to array2(i) the values of:

i=1 -- array2(1) = 3 (occurrences of "2"),
i=2 -- array2(2) = 2 (occurrences of "4"),
i=3 -- array2(3) = 2 (occurrences of "3").

Can somebody help me?

Thanks in advance :-)

Antonio.





 
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
Ranking function doverfield Excel Worksheet Functions 6 October 7th 10 12:04 PM
Ranking without preset Excel function. a.riva@UCL Excel Worksheet Functions 0 October 16th 07 05:53 PM
Ranking Function casdaq Excel Worksheet Functions 4 March 15th 07 04:50 AM
can excel draw with preset values man57 Excel Discussion (Misc queries) 6 April 17th 06 10:05 AM
Is there anyway to add more than the preset 265 columns in Excel? CarlaWood Excel Discussion (Misc queries) 6 December 8th 05 10:09 PM


All times are GMT +1. The time now is 10:05 PM.

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

About Us

"It's about Microsoft Excel"