+ Reply to Thread
Results 1 to 10 of 10

Thread: Condense duplicate data to one row, data in same column in new row

  1. #1
    Registered User
    Join Date
    10-08-2009
    Location
    Chatsworth, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Condense duplicate data to one row, data in same column in new row

    Hi,
    I have a spreadsheet that has "Parts" in the first column and "Due Dates" in the following columns. Currently, the data is spread across rows with the same part appearing more than once with different dates in different columns.

    I would like to condense the data to a single row per part but with its dates spread across columns in the same row (and remaining in its same column position as it was originally but in the new row). Preferably with VB.


    Example below:

    Existing Worksheet (Sheet1)
    A1 A2 A3 A4
    R1 Part1 10/1
    R2 Part1 10/2
    R3 Part1 10/3
    R4 Part2 10/1
    R5 Part2 10/4

    Condensed Worksheet (Sheet2)
    A1 A2 A3 A4
    R1 Part1 10/1 10/2 10/3
    R2 Part2 10/1 10/4

    I don't know if the spacing in the example will carry into the posted message so I have attached an example spreadsheet (Excel 2007).
    Thank you,
    Chris


    New Parameters:
    Condense onto same worksheet (instead of separate worksheet).
    Attached Files Attached Files
    Last edited by resmed; 10-22-2009 at 05:19 PM. Reason: Parameters changed

  2. #2
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,359

    Re: Condense duplicate data to one row, data in same column in new row

    Hi

    See how this goes.

    Sub aaa()
      Dim OutSH As Worksheet
      Set OutSH = Sheets("Sheet2")
      OutSH.Cells.ClearContents
      
      Sheets("Sheet1").Activate
      
      For Each ce In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        If WorksheetFunction.CountIf(OutSH.Range("A:A"), ce.Value) = 0 Then
          If IsEmpty(OutSH.Cells(1, 1)) Then
            outrow = 1
          Else
            outrow = OutSH.Cells(Rows.Count, 1).End(xlUp).Row + 1
          End If
          OutSH.Cells(outrow, 1).Value = ce.Value
        End If
        Set findit = OutSH.Range("A:A").Find(what:=ce.Value)
        For i = 2 To Cells(ce.Row, Columns.Count).End(xlToLeft).Column
          If Not IsEmpty(Cells(ce.Row, i)) Then
            OutSH.Cells(findit.Row, i).Value = Cells(ce.Row, i).Value
          End If
        Next i
        
      Next ce
      
    End Sub
    rylo

  3. #3
    Registered User
    Join Date
    10-08-2009
    Location
    Chatsworth, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Condense duplicate data to one row, data in same column in new row

    Thank you! That does exactly what I wanted.

    Chris

  4. #4
    Registered User
    Join Date
    10-08-2009
    Location
    Chatsworth, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Condense duplicate data to one row, data in same column in new row

    Thanks, Rylo.

    Something has changed - what if I want to perform the function on the same spreadsheet instead of copying the cells to a 2nd spreadsheet?

    Chris

  5. #5
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,359

    Re: Condense duplicate data to one row, data in same column in new row

    Hi

    One way would be to create a temporary spreadsheet, use the above macro to put it to that temporary sheet, copy from the temp over the original, then remove the temporary sheet.

    Would that suffice?

    rylo

  6. #6
    Registered User
    Join Date
    10-08-2009
    Location
    Chatsworth, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Condense duplicate data to one row, data in same column in new row

    Yes, that would be okay.
    I would need the copied cells to be put onto an existing sheet (Sheet2) that has labeling across the first 3 rows.
    So is there a way to specify that the data be copied starting at row 4?

    Thanks again.

    Chris

  7. #7
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,359

    Re: Condense duplicate data to one row, data in same column in new row

    Chris

    Put up an updated example file showing your real stucture, how it starts, and how it is to look when completed.

    ryl

  8. #8
    Registered User
    Join Date
    10-08-2009
    Location
    Chatsworth, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Condense duplicate data to one row, data in same column in new row

    Hi,
    Here is an example of the spreadsheet.

    The data is Parts (with some items such as description, cost, etc.) and Due Dates with quantity and weekday.

    Sheet "Input" has the data (brought in from an ODBC link to a database) and the various dates (with quantity and weekday) spread out across the columns based on week number.
    At this point, the spreadsheet is usable except that a single part appears on more than one row if it has more than one due date. So the only change that would need to occur is the condensing of the mentioned rows to a single row. The dates are already in the correct column, they just need to move to the first row that its related part number appears and the remaining duplicate rows of that part number deleted (after all the dates are moved to the same row).

    Sheet "Output" shows how the data should be condensed to a single row per part with the various due dates spread across the columns on the same row (note, the dates did not have to move columns, they just had to move to the first row that the part appeared).

    Rows 1-3 contain static labels. Columns 1-7 contain part number, description items such as order, customer part number, etc. These columns/rows will always contain this info. It may not always contain the same part numbers, it changes based on orders/production.

    The due dates start at column 8-63. These columns will always contain this info.

    Thank you and do let me know if you need any other info or clarification.

    Chris
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,359

    Re: Condense duplicate data to one row, data in same column in new row

    Chris

    See how this goes for the example file.

    Sub DataConsol()
      Dim OutSH As Worksheet, rng As Range
      Set OutSH = Sheets("OUTPUT")
      With OutSH
        lastrow = WorksheetFunction.Max(4, .Cells(Rows.Count, 1).End(xlUp).Row)
        .Rows("4:" & lastrow).ClearContents
      End With
      Sheets("INPUT").Select
      For Each ce In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        lastrow = WorksheetFunction.Max(5, OutSH.Cells(Rows.Count, 1).End(xlUp).Row)
        Set rng = OutSH.Range("A4:A" & lastrow)
        cnta = Evaluate("=sumproduct(--(output!" & rng.Address & "= " & ce.Address & "),--(output!" & rng.Offset(0, 1).Address & "=" & ce.Offset(0, 1).Address & "),--(output!" & rng.Offset(0, 2).Address & "=" & ce.Offset(0, 2).Address & "),--(output!" & rng.Offset(0, 3).Address & "=" & ce.Offset(0, 3).Address & "),row(output!" & rng.Address & "))")
        If cnta = 0 Then
          outrow = OutSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
          OutSH.Cells(outrow, 1).Value = ce.Value
          OutSH.Cells(outrow, 2).Value = ce.Offset(0, 1).Value
          OutSH.Cells(outrow, 3).Value = ce.Offset(0, 2).Value
          OutSH.Cells(outrow, 4).Value = ce.Offset(0, 3).Value
          OutSH.Cells(outrow, 5).Value = ce.Offset(0, 4).Value
        Else
          outrow = cnta
        End If
        
        For i = 6 To Cells(ce.Row, Columns.Count).End(xlToLeft).Column
          If Len(Cells(ce.Row, i)) > 0 Then
            OutSH.Cells(outrow, i).Value = Cells(ce.Row, i).Value
          End If
        Next i
        
      Next ce
      
      MsgBox "Completed"
    
    End Sub
    rylo

  10. #10
    Registered User
    Join Date
    01-23-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Condense duplicate data to one row, data in same column in new row

    Hey guys, sorry for bumping this old thread but this is very close to what I need. It is as close as I have gotten to finding a solution.

    I need something like the first person asked for, except one that can handle a few more columns (preferably adjustable). For instance:

    A1 A2 A3
    R1 PART1 4 5
    R2 PART1 3 7
    R3 PART1 6 8
    R4 PART1 5 6
    R5 PART2 5 3


    Would be:


    A1 A2 A3 A4 A5 A6 A7 A8 A9
    R1 PART1 4 5 3 7 6 8 5 6
    R2 PART2 5 3


    All of the data I am using may be either numerical or a character.

    Any help would be GREATLY appreciated as I am currently using a much more manual time intensive process to achieve this. This is my first post so if I did something wrong don't hesitate to haze me.

    Thanks guys.
    Last edited by WorksheetWarrior; 01-23-2012 at 01:10 PM.

+ 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.2.0