Excel连接行 [英] Excel Concatenate Rows

查看:104
本文介绍了Excel连接行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个excel工作表

I have this excel worksheet

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

现在我

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

我该怎么做,最好用GUI?

How do I do this, preferably with GUI?

推荐答案

如果你愿意写宏...

If you are willing to write a macro...

单击第一个foo1单元格并运行它。它将加入foo1,然后加入foo2,直到它打到一个空白单元格。如果你以前从来没有写过一个宏,可能我们可以通过它走走。

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

这篇关于Excel连接行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆