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 from a variant variable

When I apply your code below, I get the following error:

User-defined type not defined? How should this variable type be
defined?

Thanks.


Patrick Lee wrote:
One solution is to store your strings as keys for a
Collection or Dictionary (to use the latter, set a
reference in your VBA project to Microsoft Scripting
Runtime) object. Keys for both of these objects have to
be unique.
Personally, I would use a Dictionary object
dim dic1 as Dictionary
Set dic1 = New Dictionary

For iCounter = 1 to lYourNumberOfStrings
dim yourstring as string
' retrieve yourstring depending on iCounter
if not dic1.exists(yourstring) then
' we know that yourstring has not already been added
as a key to the dictionary
dic1.Add yourstring, 1 ' this adds yourstring as a
key and 1 as the value referenced by this key (the value
is not used here so anything will do)

end if
next iCounter

' after this loop, dic1.Keys() is an array going from 0
to dic1.Count -1 with the unique values of your strings

hth

Patrick

-----Original Message-----
I have a variant variable holding string values
How shall eliminate the duplicate strings from this
variable, retaining only one value. Eg: If i have the
element "TOM" twice in that array, i wish to delete one.
which is the most effective way to handle this?

Thanks,
Leo

.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Eliminating duplicates from a variant variable

Hi Smokiibear,

Did you set a reference to the Microsoft Scripting Runtime library, as
suggested by Patrick?

If I failed to do this, I could reproduce your error.

..
---
Regards,
Norman



"smokiibear" wrote in message
ups.com...
When I apply your code below, I get the following error:

User-defined type not defined? How should this variable type be
defined?

Thanks.


Patrick Lee wrote:
One solution is to store your strings as keys for a
Collection or Dictionary (to use the latter, set a
reference in your VBA project to Microsoft Scripting
Runtime) object. Keys for both of these objects have to
be unique.
Personally, I would use a Dictionary object
dim dic1 as Dictionary
Set dic1 = New Dictionary

For iCounter = 1 to lYourNumberOfStrings
dim yourstring as string
' retrieve yourstring depending on iCounter
if not dic1.exists(yourstring) then
' we know that yourstring has not already been added
as a key to the dictionary
dic1.Add yourstring, 1 ' this adds yourstring as a
key and 1 as the value referenced by this key (the value
is not used here so anything will do)

end if
next iCounter

' after this loop, dic1.Keys() is an array going from 0
to dic1.Count -1 with the unique values of your strings

hth

Patrick



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
Eliminating Duplicates Parker[_4_] Excel Programming 6 August 25th 04 03:57 PM


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

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

About Us

"It's about Microsoft Excel"