+ Reply to Thread
Results 1 to 10 of 10

Create Unique List based on matching value in adjacent column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Create Unique List based on matching value in adjacent column

    Hi everyone,

    I have two columns, A and B. Column A has a unique list of values, and column B has a set number of value for each value in Column A.

    What I'm trying to do is get macro that will give me a unique list of Column A values who's adjacent Column B value matches a predetermine value. I have attached a workbook to this post. This unique list of values will be pasted to column C

    So, if the user wants to create a unique list based on the value "Yes" in column B, then the corresponding unique list will be pasted into column C. For this macro, a pivot table or manually created a unique list will not work. It must be automated via VBA.

    Any ideas?

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Create Unique List based on matching value in adjacent column

    Try the attached.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Create Unique List based on matching value in adjacent column

    Hi AB33,

    Thank you very much for your macro! I'm embarrassed that I need make an error with my description and sample. Columns A and B in the sample template I attached should be in sheet 1, whereas the results column (currently column C) should be in sheet 2. Can you assist with these updates?

    Thanks very much

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,509

    Re: Create Unique List based on matching value in adjacent column

    Sub tst()
        sn = Sheets(1).Cells(1).CurrentRegion.Value
        With CreateObject("scripting.dictionary")
            For i = 1 To UBound(sn)
                If sn(i, 2) = "Y" Then x0 = .Item(sn(i, 1))
            Next
            With Sheets(2)
                .Columns(1).ClearContents
                .Cells(1).Resize(.Count) = Application.Transpose(.keys)
            End With
        End With
    End Sub
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Create Unique List based on matching value in adjacent column

    hi bakerman,

    Thanks very much for the updated code. I've made the following adjustments to match my actual workbook:

    Sub tst()
        sn = Sheets("Summary").Cells(1).CurrentRegion.Value
        With CreateObject("scripting.dictionary")
            For i = 1 To UBound(sn)
                If sn(i, 16) = "Y" Then x0 = .Item(sn(i, 14))
            Next
            With Sheets("Data")
                .Columns(1).ClearContents
                .Cells(1).Resize(.Count) = Application.Transpose(.keys)
            End With
        End With
    End Sub
    16 is the column I'm matching the data to, and column 14 is were the unique list data is coming from. I'm getting a run-time error 438: object doesn't support this property or method on the following line:

    .Cells(1).Resize(.Count) = Application.Transpose(.keys)
    Any help? Also, i'm not certain where in your code it specifies where the unique list should be pasted in sheet Data.

    Thanks for your help!

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Create Unique List based on matching value in adjacent column

    Adjusted to sheet 2
    Attached Files Attached Files

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,509

    Re: Create Unique List based on matching value in adjacent column

    Sub tst()
        sn = Sheets("Summary").Cells(1).CurrentRegion.Value
        With CreateObject("scripting.dictionary")
            For i = 1 To UBound(sn)
                If sn(i, 16) = "Y" Then x0 = .Item(sn(i, 14))
            Next
            Sheets("Data").Columns(1).ClearContents
            Sheets("Data").Cells(1).Resize(.Count) = Application.Transpose(.keys)
        End With
    End Sub

  8. #8
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Create Unique List based on matching value in adjacent column

    Thank you very much, AB33 and bakerman2

  9. #9
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Create Unique List based on matching value in adjacent column

    Maybe another option..?

    Sub Test()
    With [A1].CurrentRegion.Offset(, 2).Resize(, 1)
       .Value = [=IF(B1:B10="Y",A1:A10,"")]
       .SpecialCells(4).Delete
    End With
    End Sub
    This is just using a static range.. to introduce a variable range.. use the evaluate function (without square brackets)..

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,509

    Re: Create Unique List based on matching value in adjacent column

    You're welcome and thanks for the rep.

+ 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. Create unique # of worksheets based on list count with unique names
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-24-2016, 09:51 AM
  2. Counting unique items on a list based on date in adjacent column
    By Mafoo17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2013, 04:24 PM
  3. Replies: 3
    Last Post: 03-21-2013, 09:28 AM
  4. [SOLVED] Create a Drop down list with dates based on adjacent Cell
    By smugglersblues in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-15-2013, 02:39 PM
  5. Consolidate Unique List Items into an Adjacent Column
    By packetdog in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-09-2012, 11:29 AM
  6. Pull unique values based on adjacent column
    By freud1 in forum Excel General
    Replies: 9
    Last Post: 07-02-2012, 11:36 AM
  7. VBA: Create unique list based on latest entry in list
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-08-2011, 09:55 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