+ Reply to Thread
Results 1 to 4 of 4

Extract unique values in a column from a table

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Extract unique values in a column from a table

    I got a datafile with about 50000 rows of data where in column A there is a ID number and in column B there is a dateformat as the following, yyyyww, for example 201705 which is week 5 in the year 2017. In column A there will the same ID number appear in several rows but I only want to have one row per ID number. Therefore I need to extract all unique values in column A with each corresponding column. When a ID number has a duplicate then I only want to see the ID number with the earliest date in column B. Its possible to sort column B from the first date to the last if that helps. Anyone know how I can solve this?

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Extract unique values in a column from a table

    Hi,

    Make sure the data is sorted in date order ascending then use a helper column. Add the following formula to the first row

    Formula: copy to clipboard
    =COUNTIF($A1:A1,A1)

    Copy this down and then filter on the helper column for all the '1' values. Select the rows and copy and paste them.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Extract unique values in a column from a table

    Hi,
    Please attach slamm sample file with dummy data, but make sure the structure of file is the same as your original file.

  4. #4
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Extract unique values in a column from a table

    I tried to use a code from one of my previous projects which I think someone in here helped me with. I changed the code a bit and it looks like its working as intented but then I found out that it apparently still is a couple duplicates in column 5, did I miss something when I changed my code?

    
    Dim Rng As Range, Dn As Range, n As Long, Ray As Variant, Ac As Long, c As Long, cell As Range
    
    Ray = ActiveSheet.UsedRange
    ReDim nRay(1 To UBound(Ray, 1), 1 To UBound(Ray, 2))
    With CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
    For n = 1 To UBound(Ray, 1)
        If Not .Exists(Ray(n, 5)) Then
            c = c + 1
            For Ac = 1 To UBound(Ray, 2)
                nRay(c, Ac) = Ray(n, Ac)
            Next Ac
            .Add Ray(n, 5), c
        End If
    Next n
    Range("A:A").Resize(, UBound(Ray, 2)).ClearContents
    Range("A1").Resize(.Count, UBound(Ray, 2)).Value = nRay
    End With

+ 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. Extract unique value from column of consecutive repeated values
    By hamang in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-26-2016, 04:37 AM
  2. [SOLVED] How To: Extract unique values from 3 columns into 1 column.
    By egarcia7 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-24-2016, 12:31 PM
  3. [SOLVED] Extract unique values from a table and list along a row
    By doctorblyth in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-05-2013, 04:33 PM
  4. Replies: 2
    Last Post: 02-13-2013, 03:14 PM
  5. VBA Extract unique values depending on selected item in another column
    By DavidBW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2013, 05:30 AM
  6. Replies: 3
    Last Post: 09-20-2011, 05:05 PM
  7. Extract unique items from a Table and place in a column
    By Evilshrew in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-28-2007, 02:36 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