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

I have 5 cells going across my spreadsheet, that contain
c c c j q respectively. I want to note, in another cell,
that J Q and C have occured, but I don't want the C to
show up 3 times. How do I do this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Eliminating Duplicates

One way of doing this.
Can't remember where I got the idea from to use a collection to remove
duplicates.
I don't think it is the fastest way, but it looks nice.
To test put the data in cells A1 to F1.

Function RemoveDuplicates(ByRef arr1 As Variant) As Variant

'removes duplicates from an Excel row, passed as an array
'--------------------------------------------------------

Dim NoDupes As Collection
Dim i As Long
Dim UB As Long
Dim arr2()

Set NoDupes = New Collection

UB = UBound(arr1, 2)

'The next statement ignores the error caused
'by attempting to add a duplicate key to the collection.
'The duplicate is not added - which is just what we want!
'--------------------------------------------------------
On Error Resume Next
For i = 1 To UB
NoDupes.Add arr1(1, i), CStr(arr1(1, i))
'Note: the 2nd argument (key) for
'the Add method must be a string
'--------------------------------
Next
On Error GoTo 0

ReDim arr2(1, 1 To NoDupes.Count)

'copy the collection to the new array
'------------------------------------
For i = 1 To NoDupes.Count
arr2(1, i) = NoDupes(i)
Next

RemoveDuplicates = arr2

End Function


Sub test()

Dim i As Long
Dim strUniques As String
Dim arr()

arr = Range(Cells(1), Cells(6))

arr = RemoveDuplicates(arr)

For i = 1 To UBound(arr, 2)
strUniques = strUniques & arr(1, i)
Next

Cells(8).Value = strUniques

End Sub


RBS


"Parker" wrote in message
...
I have 5 cells going across my spreadsheet, that contain
c c c j q respectively. I want to note, in another cell,
that J Q and C have occured, but I don't want the C to
show up 3 times. How do I do this?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Eliminating Duplicates

Most of the code originated at John Walkenbach's site.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote in message
...
One way of doing this.
Can't remember where I got the idea from to use a collection to remove
duplicates.
I don't think it is the fastest way, but it looks nice.
To test put the data in cells A1 to F1.

Function RemoveDuplicates(ByRef arr1 As Variant) As Variant

'removes duplicates from an Excel row, passed as an array
'--------------------------------------------------------

Dim NoDupes As Collection
Dim i As Long
Dim UB As Long
Dim arr2()

Set NoDupes = New Collection

UB = UBound(arr1, 2)

'The next statement ignores the error caused
'by attempting to add a duplicate key to the collection.
'The duplicate is not added - which is just what we want!
'--------------------------------------------------------
On Error Resume Next
For i = 1 To UB
NoDupes.Add arr1(1, i), CStr(arr1(1, i))
'Note: the 2nd argument (key) for
'the Add method must be a string
'--------------------------------
Next
On Error GoTo 0

ReDim arr2(1, 1 To NoDupes.Count)

'copy the collection to the new array
'------------------------------------
For i = 1 To NoDupes.Count
arr2(1, i) = NoDupes(i)
Next

RemoveDuplicates = arr2

End Function


Sub test()

Dim i As Long
Dim strUniques As String
Dim arr()

arr = Range(Cells(1), Cells(6))

arr = RemoveDuplicates(arr)

For i = 1 To UBound(arr, 2)
strUniques = strUniques & arr(1, i)
Next

Cells(8).Value = strUniques

End Sub


RBS


"Parker" wrote in message
...
I have 5 cells going across my spreadsheet, that contain
c c c j q respectively. I want to note, in another cell,
that J Q and C have occured, but I don't want the C to
show up 3 times. How do I do this?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Eliminating Duplicates

Looked this up and I think the merits here must go to J.G. Hussey.

RBS


"Tom Ogilvy" wrote in message
...
Most of the code originated at John Walkenbach's site.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote in message
...
One way of doing this.
Can't remember where I got the idea from to use a collection to remove
duplicates.
I don't think it is the fastest way, but it looks nice.
To test put the data in cells A1 to F1.

Function RemoveDuplicates(ByRef arr1 As Variant) As Variant

'removes duplicates from an Excel row, passed as an array
'--------------------------------------------------------

Dim NoDupes As Collection
Dim i As Long
Dim UB As Long
Dim arr2()

Set NoDupes = New Collection

UB = UBound(arr1, 2)

'The next statement ignores the error caused
'by attempting to add a duplicate key to the collection.
'The duplicate is not added - which is just what we want!
'--------------------------------------------------------
On Error Resume Next
For i = 1 To UB
NoDupes.Add arr1(1, i), CStr(arr1(1, i))
'Note: the 2nd argument (key) for
'the Add method must be a string
'--------------------------------
Next
On Error GoTo 0

ReDim arr2(1, 1 To NoDupes.Count)

'copy the collection to the new array
'------------------------------------
For i = 1 To NoDupes.Count
arr2(1, i) = NoDupes(i)
Next

RemoveDuplicates = arr2

End Function


Sub test()

Dim i As Long
Dim strUniques As String
Dim arr()

arr = Range(Cells(1), Cells(6))

arr = RemoveDuplicates(arr)

For i = 1 To UBound(arr, 2)
strUniques = strUniques & arr(1, i)
Next

Cells(8).Value = strUniques

End Sub


RBS


"Parker" wrote in message
...
I have 5 cells going across my spreadsheet, that contain
c c c j q respectively. I want to note, in another cell,
that J Q and C have occured, but I don't want the C to
show up 3 times. How do I do this?





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Eliminating Duplicates

John is pretty straightforward about his sources. Based on what he says,
the code appears to be an original implementation of an idea of J.G Hussey.

For instance
http://www.devx.com/tips/Tip/12038

Since most of your code is a direct lift from John's site, I think the
merits must go to John.

Or maybe this guy thought it all up:

http://www.win-consult.com/Tips/Libr...NoDuplica tes
he copyrighted it in 2001

Can't remember where I got the idea from to use a collection to remove
duplicates.

Seems like you used much more than the idea to use a collection since your
code is pretty much identical to John's
Not sure why you want to begrudge John credit for his work.

--
Regards,
Tom Ogilvy





"RB Smissaert" wrote in message
...
Looked this up and I think the merits here must go to J.G. Hussey.

RBS


"Tom Ogilvy" wrote in message
...
Most of the code originated at John Walkenbach's site.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote in message
...
One way of doing this.
Can't remember where I got the idea from to use a collection to remove
duplicates.
I don't think it is the fastest way, but it looks nice.
To test put the data in cells A1 to F1.

Function RemoveDuplicates(ByRef arr1 As Variant) As Variant

'removes duplicates from an Excel row, passed as an array
'--------------------------------------------------------

Dim NoDupes As Collection
Dim i As Long
Dim UB As Long
Dim arr2()

Set NoDupes = New Collection

UB = UBound(arr1, 2)

'The next statement ignores the error caused
'by attempting to add a duplicate key to the collection.
'The duplicate is not added - which is just what we want!
'--------------------------------------------------------
On Error Resume Next
For i = 1 To UB
NoDupes.Add arr1(1, i), CStr(arr1(1, i))
'Note: the 2nd argument (key) for
'the Add method must be a string
'--------------------------------
Next
On Error GoTo 0

ReDim arr2(1, 1 To NoDupes.Count)

'copy the collection to the new array
'------------------------------------
For i = 1 To NoDupes.Count
arr2(1, i) = NoDupes(i)
Next

RemoveDuplicates = arr2

End Function


Sub test()

Dim i As Long
Dim strUniques As String
Dim arr()

arr = Range(Cells(1), Cells(6))

arr = RemoveDuplicates(arr)

For i = 1 To UBound(arr, 2)
strUniques = strUniques & arr(1, i)
Next

Cells(8).Value = strUniques

End Sub


RBS


"Parker" wrote in message
...
I have 5 cells going across my spreadsheet, that contain
c c c j q respectively. I want to note, in another cell,
that J Q and C have occured, but I don't want the C to
show up 3 times. How do I do this?








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Eliminating Duplicates

Tom,

I think unless the code is truly amazing and fantastic it is a bit of a
waste of time to get into an argument where
it originated from. Most programmers must have lots of code that they can't
remember where it originated from.
They might know where they got it from but that is not the same as who wrote
it in the first place.
I can see now that the code in question for a large part came from John
Walkenbach and credit to him.
I think though that the essential bit came from J.G. Hussey as John said
himself to credit to him as well.
When I post a bit of code I never claim to have written it in the first
place, all I do is help somebody with a problem.
I think it would be a waste of time if everytime somebody posted a bit of
code he had to trace where it originated from
and mention that in the post. I agree though that in general it is better to
refer to somebody's website or less so to another newgroup posting if the
problem was solved before.

RBS


"Tom Ogilvy" wrote in message
...
John is pretty straightforward about his sources. Based on what he says,
the code appears to be an original implementation of an idea of J.G

Hussey.

For instance
http://www.devx.com/tips/Tip/12038

Since most of your code is a direct lift from John's site, I think the
merits must go to John.

Or maybe this guy thought it all up:


http://www.win-consult.com/Tips/Libr...NoDuplica tes
he copyrighted it in 2001

Can't remember where I got the idea from to use a collection to

remove
duplicates.

Seems like you used much more than the idea to use a collection since your
code is pretty much identical to John's
Not sure why you want to begrudge John credit for his work.

--
Regards,
Tom Ogilvy





"RB Smissaert" wrote in message
...
Looked this up and I think the merits here must go to J.G. Hussey.

RBS


"Tom Ogilvy" wrote in message
...
Most of the code originated at John Walkenbach's site.

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote in message
...
One way of doing this.
Can't remember where I got the idea from to use a collection to

remove
duplicates.
I don't think it is the fastest way, but it looks nice.
To test put the data in cells A1 to F1.

Function RemoveDuplicates(ByRef arr1 As Variant) As Variant

'removes duplicates from an Excel row, passed as an array
'--------------------------------------------------------

Dim NoDupes As Collection
Dim i As Long
Dim UB As Long
Dim arr2()

Set NoDupes = New Collection

UB = UBound(arr1, 2)

'The next statement ignores the error caused
'by attempting to add a duplicate key to the collection.
'The duplicate is not added - which is just what we want!
'--------------------------------------------------------
On Error Resume Next
For i = 1 To UB
NoDupes.Add arr1(1, i), CStr(arr1(1, i))
'Note: the 2nd argument (key) for
'the Add method must be a string
'--------------------------------
Next
On Error GoTo 0

ReDim arr2(1, 1 To NoDupes.Count)

'copy the collection to the new array
'------------------------------------
For i = 1 To NoDupes.Count
arr2(1, i) = NoDupes(i)
Next

RemoveDuplicates = arr2

End Function


Sub test()

Dim i As Long
Dim strUniques As String
Dim arr()

arr = Range(Cells(1), Cells(6))

arr = RemoveDuplicates(arr)

For i = 1 To UBound(arr, 2)
strUniques = strUniques & arr(1, i)
Next

Cells(8).Value = strUniques

End Sub


RBS


"Parker" wrote in message
...
I have 5 cells going across my spreadsheet, that contain
c c c j q respectively. I want to note, in another cell,
that J Q and C have occured, but I don't want the C to
show up 3 times. How do I do this?







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
Eliminating duplicates Harish Excel Discussion (Misc queries) 2 September 26th 09 03:46 PM
Eliminating Duplicates in Excel 2007 Té Excel Worksheet Functions 2 June 11th 09 11:19 PM
Need help eliminating text duplicates! Excelhelp Excel Discussion (Misc queries) 1 June 19th 07 04:03 PM
is it possible to combine data sets, eliminating duplicates? [email protected] Excel Worksheet Functions 1 April 25th 07 05:01 PM
#N/A and eliminating it. Ted Excel Discussion (Misc queries) 2 April 24th 07 05:26 PM


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