返回列表 上一主題 發帖

5選2排列組合

回復 1# eric7765

資料擺放位置請自行調整
Sub ex()
Dim a As Object, X%, Y%
Y = 1
For Each a In Range([a1], [a1].End(4))
   For X = a.Row + 1 To [a1].End(4).Row
      Cells(Y, 3) = "[" & Format(Cells(a.Row, 1), "0#") & "." & Format(Cells(X, 1), "0#") & "]"  '資料放置於欄位(C)
      Y = Y + 1
   Next
Next
End Sub

TOP

回復 5# dou10801
5選2
Sub ex1()
Dim a As Object, b As Object, X%, Y%
Range([a7], [a7].End(4)).Clear
Y = 7
For Each a In [a1].CurrentRegion.Columns
   For Each b In a.Rows
      For X = b.Row + 1 To Cells(1, b.Column).End(4).Row
         Cells(Y, 1) = "[" & Format(Cells(b.Row, b.Column), "0#") & "." & Format(Cells(X, b.Column), "0#") & "]"
         Y = Y + 1
      Next
   Next
Next
End Sub

5選3
Sub ex2()
Dim a As Object, b As Object, X%, Y%
Range([a7], [a7].End(4)).Clear
Y = 7
For Each a In [a1].CurrentRegion.Columns
   For Each b In a.Rows
      For X = b.Row + 1 To Cells(1, b.Column).End(4).Row
         If X + 1 <= Cells(1, b.Column).End(4).Row Then
            Cells(Y, 1) = "[" & Format(Cells(b.Row, b.Column), "0#") & "." & Format(Cells(X, b.Column), "0#") & "." & Format(Cells(X + 1, b.Column), "0#") & "]"
            Y = Y + 1
         End If
      Next
   Next
Next
End Sub

TOP

回復 7# eric7765

5選2
Sub ex1()
Dim a As Object, b As Object, X%, Y%
[a7].CurrentRegion.ClearContents
Y = 7
For Each a In [a1].CurrentRegion.Columns
   For Each b In a.Rows
      For X = b.Row + 1 To Cells(1, b.Column).End(4).Row
         Cells(Y, b.Column) = "[" & Format(Cells(b.Row, b.Column), "0#") & "." & Format(Cells(X, b.Column), "0#") & "]"
         Y = Y + 1
      Next
   Next
   Y = 7
Next
End Sub

5選3
Sub ex2()
Dim a As Object, b As Object, X%, Y%
[a7].CurrentRegion.ClearContents
Y = 7
For Each a In [a1].CurrentRegion.Columns
   For Each b In a.Rows
      For X = b.Row + 1 To Cells(1, b.Column).End(4).Row
         If X + 1 <= Cells(1, b.Column).End(4).Row Then
            Cells(Y, b.Column) = "[" & Format(Cells(b.Row, b.Column), "0#") & "." & Format(Cells(X, b.Column), "0#") & "." & Format(Cells(X + 1, b.Column), "0#") & "]"
            Y = Y + 1
         End If
      Next
   Next
   Y = 7
Next
End Sub

TOP

        靜思自在 : 生氣,就是拿別人的過錯來懲罰自己。
返回列表 上一主題