Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Eliminating duplicates | Excel Discussion (Misc queries) | |||
Eliminating Duplicates in Excel 2007 | Excel Worksheet Functions | |||
Need help eliminating text duplicates! | Excel Discussion (Misc queries) | |||
is it possible to combine data sets, eliminating duplicates? | Excel Worksheet Functions | |||
#N/A and eliminating it. | Excel Discussion (Misc queries) |