Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

numbers in an Array are the Same?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frankbelly - 26 Nov 2006 01:12 GMT
I am adding numbers to an Array via the users selection (user selects a
number and it adds it to an array).  What I need is a way to check if there
are two or more numbers that are exactly the same inside the Array.  I need
to find out which numbers are duplicates, triplicates, etc.

Any help is greatly appreciated.  Thanks.
Jezebel - 26 Nov 2006 02:11 GMT
One approach is to use a collection rather than an array. Create a key from
the number, something like

on error resume next
MyCollection.Add Item:=MyNum, Key:=  "_" & format(MyNum, "0000")
if err.Number <> 0 then
   ... MyNum has been added already

>I am adding numbers to an Array via the users selection (user selects a
> number and it adds it to an array).  What I need is a way to check if
[quoted text clipped - 4 lines]
>
> Any help is greatly appreciated.  Thanks.
Frankbelly - 27 Nov 2006 01:20 GMT
Hi Jezebel,

Thank you so much for your resolution and I believe this is definitely what
I need to use only my skills are extremely low and I have never used "Add
Item" in VBA.  I tried looking through the help files, but it still seems
confusing to me.

I'm using this in a document where you have a set of statements with numbers
at the end.  I am checking to make sure no two statements have the same
number at the end.  Example of statements in the document:

--------------------------------------------------
INTERROGATORY RESPONSE NO. 1

A paragraph of text. The quick brown fox jumps over the lazy dog.  The quick
brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy
dog.

INTERROGATORY RESPONSE NO. 2

A paragraph of text. The quick brown fox jumps over the lazy dog.  The quick
brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy
dog.

INTERROGATORY RESPONSE NO. 3

A paragraph of text. The quick brown fox jumps over the lazy dog.  The quick
brown fox jumps over the lazy dog.  The quick brown fox jumps over the lazy
dog.
--------------------------------------------------

I am checking to see if any two or more INTERROGATORY RESPONSE statements in
the document end in the same number.  If so, I need to flag these duplicate
numbers by highlighting them in yellow.

> One approach is to use a collection rather than an array. Create a key from
> the number, something like
[quoted text clipped - 12 lines]
> >
> > Any help is greatly appreciated.  Thanks.
Jezebel - 27 Nov 2006 02:30 GMT
Read help on Collections. The instruction is 'Add' -- Item and Key are the
arguments. Apart from the VBA help itself, Google for any of dozens of VB or
VBA tutorial sites (collections are pretty much the same in both). In brief,
a collection is an arbitrary list of Key-Item pairs. The Keys must be
unique, and it makes life easier if they are strings. The items are usually
objects, but can be anything, including literal values.

If your exercise is just a one-off to check for duplications (as opposed to
something you will need to do repeatedly), make a copy of your document,
select all, and sort. Then all your INTERROGATORY RESPONSE lines will come
together, and you can check visually for duplications (or if you really have
squillions, check the MVPS site for how to use Find to look for duplicated
paragraphs).

> Hi Jezebel,
>
[quoted text clipped - 58 lines]
>> >
>> > Any help is greatly appreciated.  Thanks.
Frankbelly - 28 Nov 2006 21:19 GMT
This is great!  Thanks, again, for pointing me in the right direction.

> Read help on Collections. The instruction is 'Add' -- Item and Key are the
> arguments. Apart from the VBA help itself, Google for any of dozens of VB or
[quoted text clipped - 72 lines]
> >> >
> >> > Any help is greatly appreciated.  Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.