Results 1 to 8 of 8

How to Merge multiple duplicate rows into columns

Threaded View

  1. #1
    Registered User
    Join Date
    03-17-2012
    Location
    Manila, Phlippines
    MS-Off Ver
    Excel 2007
    Posts
    7

    How to Merge multiple duplicate rows into columns

    Hi there this is a repost of my problem last night since my first post was wrongly done... anyhow here's my problem:

    i have this data that have lots of duplicate rows wherein they are the date a certain employee have had his time punch what i want to accomplish is that each date would be having only one row of 2 punch_in and 2 punch out.

    here's my workbook: for testing.xlsm

    simply put i want my the data in my rawdata sheet to appear like the one i have in sheet1

    also i found a working code here though it yields an almost similar result though its not the one that i needed

    here's the code:
    Sub x()
    
    Dim rInput As Range, oDic As Object, sNames() As String, vInput()
    Dim i As Long, nIndex As Long
    
    Set rInput = Range("A1", Range("B65536").End(xlUp))
    vInput = rInput.Value
    ReDim sNames(1 To UBound(vInput, 1), 1 To 2)
    Set oDic = CreateObject("Scripting.Dictionary")
    
    With oDic
        For i = 1 To UBound(vInput, 1)
            If Not .Exists(vInput(i, 1)) Then
                nIndex = nIndex + 1
                sNames(nIndex, 1) = vInput(i, 1)
                sNames(nIndex, 2) = vInput(i, 2)
                .Add vInput(i, 1), nIndex
            ElseIf .Exists(vInput(i, 1)) Then
                sNames(.Item(vInput(i, 1)), 2) = sNames(.Item(vInput(i, 1)), 2) & ", " & vInput(i, 2)
            End If
        Next i
    End With
    
    Cells(1, "H").Resize(nIndex, 2) = sNames
    ' The line below if you want the words in separate columns
    ' otherwise they are in a single cell, separated by commas
    Cells(1, "I").Resize(nIndex).TextToColumns , comma:=True
    
    End Sub
    thank you in advance for your help
    Last edited by geiollex; 03-18-2012 at 08:20 PM.

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