2014-03-27 32 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

:) - 之前完成的一切都很簡單! - 很高興我能幫上忙!! :) –