开发者

Excel Concatenate Rows

I have this excel worksheet

A          B          c   
foo1   开发者_运维百科    joo1       loo1
foo1       joo2       loo2
foo2       joo3       loo3
foo2       joo4       loo4
foo2       joo5       loo5

Now I want this

A          B                  c   
foo1       joo1, joo2         loo1, loo2
foo2       joo3, joo4, joo5   loo3, loo4, loo5

How do I do this, preferably with GUI?


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


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜