Thanks JE
Nice and straightforward, love it
"JE McGimpsey" wrote:
> One way:
>
> Dim myCollection As Collection
> Dim MyArray As Variant
> Dim rTemp As Range
> Dim r As Long
> Dim c As Long
> Dim i As Long
>
> Set myCollection = New Collection
> Set rTemp = Sheets("MySheet").Range("rng")
> MyArray = rTemp.Value
> '// Load Array into collection, eliminate dupes
> For r = 1 To UBound(MyArray, 1)
> For c = 1 To UBound(MyArray, 2)
> If Not IsEmpty(MyArray(r, c)) Then
> On Error Resume Next
> myCollection.Add MyArray(r, c), "Key " & MyArray(r, c)
> On Error GoTo 0
> End If
> Next
> Next
>
> For i = 1 To myCollection.Count
> Debug.Print myCollection(i), _
> Application.CountIf(rTemp, myCollection(i))
> Next i
>
> In article <0449084B-AF2B-49ED-AE8D-(E-Mail Removed)>,
> David <(E-Mail Removed)> wrote:
>
> > Hi,
> > I'm summarising the contents of a range in a report. Each cell in the range
> > contains text or is empty. I've loaded the range into a variant array, then
> > looped thro the array and loaded a NewCollection using the .Add [Key'] arg to
> > eliminate duplicates. I would now like to loop thro the NewCollection and
> > count occurrences of each string in the array. What is the neatest way to do
> > this?
> > My code:
> > MyArray = Sheets("MySheet").Range("rng").Value
> > '// Load Array into collection, eliminate dupes
> > For r = 1 To UBound(MyArray, 1)
> > For c = 1 To UBound(MyArray, 2)
> > If Not IsEmpty(MyArray(r, c)) Then
> > On Error Resume Next
> > myCollection.Add MyArray(r, c), "Key " & MyArray(r, c)
> > On Error GoTo 0
> > End If
> > Next
> > Next
> >
> > For i = 1 To myCollection.Count
> > 'code required here
> > Next
> >
> > Thanks
>
|