Excel Concatenate Rows

后端 未结 3 1218
夕颜
夕颜 2020-12-12 06:18

I have this excel worksheet

A          B          c   
foo1       joo1       loo1
foo1       joo2       loo2
foo2       joo3       loo3
foo2       joo4               


        
相关标签:
3条回答
  • 2020-12-12 06:42

    If you are willing to write a macro...

    Click the first "foo1" cell and run this. It will join the foo1's then the foo2's until it hits a blank cell. If you've never written a macro before perhaps we can walk you thru it.

    Sub JoinThem()
       ' Go until blank cell (first click at upper left of range)
       Do While ActiveCell.Value <> ""
          ' If this row macthes the next row
          If ActiveCell.Value = ActiveCell.Offset(1, 0).Value Then
             ' Join first column overwriting the values
             ActiveCell.Offset(0, 1) = ActiveCell.Offset(0, 1).Value & ", " & ActiveCell.Offset(1, 1).Value
             ' and Join the second column too
             ActiveCell.Offset(0, 2) = ActiveCell.Offset(0, 2).Value & ", " & ActiveCell.Offset(1, 2).Value
             ' Since we placed the data into one row get rid of the row
             ActiveCell.Offset(1, 0).EntireRow.Delete
          Else
             ' Next row does not match, move down one
             ActiveCell.Offset(1, 0).Select
          End If
       Loop 
    End Sub
    
    0 讨论(0)
  • 2020-12-12 06:50

    Also you could use Salstat2, and the following steps

    1- import the data by using the option open in the file menu

    2- Into the script panel you should write

    # getting the colums
    res= group()
    res.xdata=  [ grid.GetCol('A')]
    res.ydata=  [ grid.GetCol('B'), grid.GetCol('C')]
    res.yvalues= ['concat(B)','concat(C)'] # concat is a function used to concatenate the data
    report.addPage() # adding a new sheet to put the results
    for lis in res.getAsRow():
       report.addRowData( lis) # adding the results row by row
    

    3- more information here

    0 讨论(0)
  • 2020-12-12 06:58

    Glad you found a solution. I'd have also recommended a pivot table. No coding required, just drag & drop your fields into the Row box. Then let Excel filter out the duplicates for you.

    0 讨论(0)
提交回复
热议问题