2014-03-27 24 views
0

我的Excel文档中的内容:没有重复的Excel排列从值多列

A  B  
Abc 12:34 
Def 56:78 
Ghi 90:12 
Jkl 34:56 
... 

我要实现这些价值观是什么:

C D  E F 
Abc 12:34 Def 56:78 
Abc 12:34 Ghi 90:12 
Abc 12:34 Jkl 34:56 
Def 56:78 Ghi 90:12 
Def 56:78 Jkl 34:56 
Ghi 90:12 Jkl 34:56 
... 

说明:

列将B可以包含文本和数字的任意组合(如果这很重要),该示例仅显示最常见的结构。它应该创建仅用于“在途中”的行的组合,即i。即“Abc ... Def ...”就足够了,不应该有“Def ... Abc ...”。

有很多例子,但我很努力地找到这样的VBA版本,可以使用多列并且不重复组合。

下面是一个简单的例子。但是,它是只有一列,它也重复值:

http://www.mrexcel.com/forum/excel-questions/412952-create-list-all-pair-combinations.html#post2046893

预先感谢您。

+0

给出你的例子,这可以用一个简单的双循环来完成......不是吗? –

+0

我真的不知道,我不是Excel的专家,但大多数关于排列的其他问题的答案都涉及宏。此外,我的一些床单将有30-40行,因此任何涉及选择需要在之后填充的X行的事情都不是很实际。如果这是双循环如何在Excel中工作。 :) – take2

+0

否 - 答案会涉及到编程/ VBA - 但我所说的是,如果你看看你的答案,你沿着每一行往下走,然后将它与所有行相结合,然后向下移动到下一个并再次做这个过程......这有道理吗? –

回答

2

鉴于我们在谈话中讨论,这里是在VBA的解决方案:

Sub CreatePermutation() 

Dim FirstCell As Integer 
Dim SecondCell As Integer 
Dim NumRows As Integer 
Dim OutputRow As Long 

    ' Get the total number of rows in column A 
    NumRows = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row() 

    ' You want to start outputting in row 1 
    OutputRow = 1 

    For FirstCell = 1 To NumRows - 1 
     For SecondCell = FirstCell + 1 To NumRows 

      ' Put in the data from the first cell into columnc C & D 
      Cells(OutputRow, 3).Value = Cells(FirstCell, 1).Value 
      Cells(OutputRow, 4).Value = Cells(FirstCell, 2).Value 

      ' Put in the data from the second cell into column E & F 
      Cells(OutputRow, 5).Value = Cells(SecondCell, 1).Value 
      Cells(OutputRow, 6).Value = Cells(SecondCell, 2).Value 

      ' Move to the next row to output 
      OutputRow = OutputRow + 1 

     Next SecondCell 
    Next FirstCell 
End Sub 

希望这完成你希望做什么。

+0

哇,你看起来很简单。 :)这正是我需要的,谢谢! – take2

+0

:) - 之前完成的一切都很简单! - 很高兴我能帮上忙!! :) –