PC Review


Reply
Thread Tools Rate Thread

Counting number of occurrences.

 
 
a.riva@UCL
Guest
Posts: n/a
 
      25th Oct 2007
Thanks for all the suggestions!

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.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      25th Oct 2007
Use the techniques here to get a unique list of items

http://www.j-walk.com/ss/excel/tips/tip47.htm

then use that unique list with your usual 1-based array to loop through it
an count the items for each. Not sure how meaningful your 1-D result array
would be since it isn't tied to what items are duplicated.

Work up your code, then post back for critique if you think you are having
problems.

--
regards,
Tom Ogilvy


"a.riva@UCL" wrote:

> Thanks for all the suggestions!
>
> 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.
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting Number of Occurrences in worksheets Terri Microsoft Excel Misc 7 5th Aug 2009 08:35 PM
Counting the number of occurrences... Zakhary Microsoft Excel Worksheet Functions 2 3rd May 2009 07:36 PM
Counting number of occurrences. a.riva@UCL Microsoft Excel Worksheet Functions 1 28th Oct 2007 03:44 AM
Counting number occurrences thermometer Microsoft Excel Discussion 3 6th Jun 2006 08:06 PM
Counting number of occurrences =?Utf-8?B?THlsZUJfQXVzdGlu?= Microsoft Excel Worksheet Functions 1 15th Sep 2005 10:42 PM


Features
 

Advertising
 

Newsgroups
 


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