使用Excel将行移动到重复行上的列?

我有一个如下所示的Excel表格,分为两栏:

Tom Alaska Tom Hawaii Tom New York Tom California Bob North Carolina Bob New York Bob Maine Bob Alaska Bob Wyoming 

我需要这样的格式:

 Tom Alaska Hawaii New York California Bob North Carolina New York Maine Alaska Wyoming 

我搜查了网站和这个网站,但我真的不知道如何提出这个问题。 对不起,如果这看起来很简单,我试过透视表,但不能以我上面描述的格式得到它。 我已经search了数据透视表到列,但是这只是让我提示转置行和列,这不是我所需要的。

任何帮助,将不胜感激。

谢谢,汤姆这是我在Excel中要做的一个例子

这是一个VBA子程序,将为你做这个。 我评论了它的鼻涕,所以你可以理解它,并根据需要改变事情:

 Sub transpoooooooooOOOOooose() Dim rngCell As Range 'variable to hold which cell we are on Dim intCol As Integer 'variable to hold the column we are writing to Dim intRow As Integer 'variable to hold the row we are writing to. Dim strGuysName As String 'variable to hold the name of the dude 'first we will write to column 2 (column 1 will contain the name of the guy) intCol = 2 'and row 0 (it will be popped up to row 1 in the first iteration intRow = 0 'Those will be increased as we iterate below 'iterate through every filled out cell in column A For Each rngCell In Sheet1.Range("A:A") If rngCell.Value = "" Then Exit Sub 'we hit the bottom of the list, exit 'If this is a new dude, then increase intRow ' and capture the name ' and send intCol back to 2 If rngCell.Value <> strGuysName Then intRow = intRow + 1 'see, we popped it up one. strGuysName = rngCell.Value intCol = 2 End If 'Now... the meat and potatoes Sheet2.Cells(intRow, 1).Value = strGuysName 'write out the guys name Sheet2.Cells(intRow, intCol).Value = rngCell.Offset(, 1).Value 'write out the city which is one column over 'increase the intCol by 1 intCol = intCol + 1 Next End Sub 

你也可以用前端excel的东西做到这一点。

首先,从列A中得到一个独特的家伙名单,并将这些名字粘贴在一张新的表格中(表2)

然后,在Sheet2!B1 (Tom旁边)中使用:

 =IF(INDEX(Sheet1!$A:$A, MATCH($A1,Sheet1!$A:$A, 0) + COLUMN() - 2)=$A1, INDEX(Sheet1!$B:$B, MATCH($A1,Sheet1!$A:$A, 0) + COLUMN() - 2), "") 

那只野兽会在Sheet1(你的原始列表)中find“Tom”并返回find的那一行。 然后它将下降的行数等于该公式在-2的列(因为我们从B开始)。 因此,列B版本检查第一行“汤姆”被find,然后列C版本发现后一行,和列D查找一行之后。 如果这个单元格中的任何行数都是“Tom”,那么执行相同的逻辑,但是抓住B中的任何一个。

非常感谢每个人,我会尝试你的每一个build议。 我继续浏览这个网站,我发现了一个类似的问题,他们用Excel公式来做到这一点:

在Excel中将重复条目与唯一数据结合在一起

基本上第三列将B列中的值合并为逗号分隔值,第四列将用于唯一标识列A中重复列表中的最后一行,然后我想我可以过滤出来,然后使用逗号分隔符把第三列分成单独的列。

我认为这个解决scheme是可行的,但我也会尝试这些其他的build议。 再一次,我欣赏这一点!

谢谢,汤姆