+ Reply to Thread
Results 1 to 2 of 2

Looking for duplicates and merging into a single row

Hybrid View

  1. #1
    Registered User
    Join Date
    09-19-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1

    Looking for duplicates and merging into a single row

    Hello all,
    The problem I am trying to figure out is how to check to see if one variable is a duplicate, and if so, to merge the data of the duplicates into one row. I attached a sample of what I am doing. So, specifically what I want to do is check to see if "173" for example appears twice in nquest, and if so, to merge the rows so that there is only one 173, and in that row, nonoc is 0 and c is 19600. Also, if the number nquest is not a duplicate, I want to drop it. Thank you so much for your help and let me know if I need to explain it further.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,681

    Re: Looking for duplicates and merging into a single row

    Try
    
    Option Explicit
    
    Sub test()
        Dim a, i As Long, ii As Long, w, y, n As Long
        With Range("a1").CurrentRegion
            a = .Value
            ReDim w(1 To .Columns.Count)
            With CreateObject("Scripting.Dictionary")
                For i = 1 To UBound(a, 1)
                    If Not .exists(a(i, 1)) Then
                        .Item(a(i, 1)) = Empty
                    End If
                    If IsEmpty(.Item(a(i, 1))) Then
                        ReDim w(1 To UBound(a, 2))
                    Else
                        w = .Item(a(i, 1))
                    End If
                    For ii = 1 To UBound(a, 2)
                        If a(i, ii) <> "" Then w(ii) = a(i, ii)
                    Next
                    .Item(a(i, 1)) = w
                Next
                y = .items: n = .Count
            End With
            With .Offset(, .Columns.Count + 1).Resize(n)
                .CurrentRegion.ClearContents
                .Value = Application.Transpose(Application.Transpose(y))
            End With
        End With
    End Sub
    Attached Files Attached Files

+ 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