+ Reply to Thread
Results 1 to 6 of 6

Finding unique table values and assigning an UID without extracting or removing data

  1. #1
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Finding unique table values and assigning an UID without extracting or removing data

    Much about extracting unique values into collection and arrays but I don't need the data extracted. I need to have each unique value in column (D) to have an associated identifier in column (A). I want to retain the data integrity (no duplicate removal) but have Excel VBA loop through column (D) and assign a UID to column (A) in the row that unique value in D resides. The UID would start with 1, then 2, and 3, and so forth (i +1). It seems like it would be a simple process, however since there are potential for many duplicates not in sequential order, I don't know the best way to approach this.

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Finding unique table values and assigning an UID without extracting or removing data

    In general, if you have a table, say B5:Z10004 with column labels in B4:Z4, one of the simpler ways to handle duplicates would be to enter 1 in AA5, 2 in AA6, select AA5:AA6 and double-click the fill handle in the bottom-right corner of AA6 to fill sequential integers into AA5:AA10004. Then sort B5:AA1004 on column D in ascending order. Then in column A,

    A5: 1
    A6: =A5+(D6<>D5)

    Fill A6 down into A7:A10004. Select A5:A10004, copy, and paste special as values on top of itself. Then sort A5:AA10004 on column AA in ascending order. That's assuming you want the same UID for each column D value which appears multiple times.

  3. #3
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Finding unique table values and assigning an UID without extracting or removing data

    I would prefer to not use helper columns and all that sorting. I don't want the UID for each record (row) either, just for the first occurrence.
    It's looking like I might have to use a collection to gather the variables x, remove the duplicates, then loop the collection back into the table for the first occurrence of variable x, then offset (to A) a value of i + 1, next x....etc.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Finding unique table values and assigning an UID without extracting or removing data

    Hi Terriertrip,

    See if this kind of formula in column B does what you want.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    UID from Duplicates.xlsx
    Press F9 a few times to recalculate my random column A to check.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Finding unique table values and assigning an UID without extracting or removing data

    If the records start in row 5,

    A5: 1
    A6: =IFERROR(MAX(A$5:A5)+ERROR.TYPE(MATCH(D6,D$5:D5,0))^0,"")

    Fill A6 down as far as needed. Once that's done, consider copying the col A range and pasting it special as values on top of itself.

    ADDED: too broad, change the formula to

    A6: =IFERROR(MAX(A$5:A5)+1/ISNA(MATCH(D6,D$5:D5,0)),"")
    Last edited by hrlngrv; 10-11-2020 at 12:34 AM.

  6. #6
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Finding unique table values and assigning an UID without extracting or removing data

    After researching this evening, I was able to get a better result using an array as opposed to a collection. The code below loops through a range storing the unique values in an array. I included blanks in the array because my data is time based and the end result needed to remain preserved to the original dimension, but one could set any parameter one chooses. The array then is spit back out to a helper column (I wrote back to the original column to save a step, but the blank values overwrote the data, so had to use the helper column). I applied a simple loop to apply a UID when x <> "".

    Code:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 11-22-2016, 06:11 AM
  2. [SOLVED] Finding Unique Values In Multiple Columns and Removing Them
    By gibbsa08 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2015, 10:39 PM
  3. Finding unique values in 2 sets of data
    By benzine in forum Excel General
    Replies: 6
    Last Post: 12-13-2014, 09:33 PM
  4. [SOLVED] Data Analysis: Comparing 3 columns, sorting, removing unique values, display data
    By kmills2626 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-14-2013, 07:27 AM
  5. Replies: 2
    Last Post: 10-19-2010, 01:59 PM
  6. [SOLVED] Extracting unique entries and assigning it to a named range
    By Hari in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-13-2005, 02:35 AM
  7. [SOLVED] Re: Extracting unique entries and assigning it to a named range
    By Hari in forum Excel General
    Replies: 0
    Last Post: 12-13-2005, 02:35 AM

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