+ Reply to Thread
Results 1 to 5 of 5

Detect/find Duplicate Values In Code

  1. #1
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Detect/find Duplicate Values In Code

    I HAVE
    RANDOM 5 FIGURE VALUES
    IN A COLUMN
    (ITS A UNIQUE CODE)

    OBTAINED BY
    Please Login or Register  to view this content.
    BUT
    THERE IS A SLIGHT CHANCE THAT THESE TWO WILL BE THE SAME ONE TIME OR ANOTHER SO MID CODE I WANT TO CHECK IT THE RANDOM NUMBER IS THE SAME IN THE WHOLE COLUMN AND IF SO DO TH ABOVE CODE AGAIN UNTIL ITS NOT

    POSSIBLE??
    I dont like to use code i dont understand
    it makes it hard to use in other situations
    so please try to be as clear and patent as possible with me

    Criticism is welcomed

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello FRIEL,

    An easier method would be to check each number as it is generated against an array. Each element of the array corresponds directly to the number generated. If the array element is zero then that number hasn't been generated.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266
    OK THAT LOOKS LIKE IT WILL WORK ILL LET U NO
    BUT IN THE MEANTIME

    A FEW QURSTIONS
    DOES THE _ AT THE END MEEN IT WILL CARRY ONTO THE NEXT LINE

    AND WHY DOES THE RANDNUMBERS HAVE (99999) IN IT~??

    ALSO
    DONT QUITE UNDER STAND
    Please Login or Register  to view this content.
    SORRY TO ASK SO MUCH
    THO SOME ARE PROBS NOOB QUESTIONS

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello FRIEL,

    The underscore character _ signals VBA that the line continues.

    The 99999 for the array is used because you are generating 5 digit decimal numbers. The lowest random number would be 0 and the highest 99999. Each one is saved into a unique memory location. The location (element address) equals the random number. Once a number is generated, a 1 is stored in that location to indicate that number has now been used. The code will look at this flag and generate another random number if it is not zero.

    Example
    The number 12345 is generated. The code looks at that array element in RandNums: RandNums(12345). If this number has not been generated before, RandNums(12345) will be 0. Now that the number has been generated, the location is flagged with a 1 to indicate this is no longer a unique random number.

    Sincerely,
    Leith Ross

  5. #5
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266
    i got an error when i did that code
    it was overflow error
    hmm
    i have ont that works but it went back to loop macros
    Please Login or Register  to view this content.

    any way of shortening it?

    or changing?
    its kinda messy

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1