Option Explicit
Sub TEST_20210927()
Dim i&, C&, Arr, Brr, x&
Arr = Array(1, 10, 100, 1000, 10000)
ReDim Brr(0 To 100, 1)
C = 0
For i = 0 To UBound(Arr)
Brr(C, 0) = Arr(i)
Brr(C, 1) = "單一"
C = C + 1
Next
For i = 0 To UBound(Arr)
For x = i + 1 To UBound(Arr)
Brr(C, 0) = Arr(i) + Arr(x)
Brr(C, 1) = "2個相加"
C = C + 1
Next
Next
For i = 0 To UBound(Arr) - 1
For x = i + 1 To UBound(Arr) - 1
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1)
Brr(C, 1) = "3個相加"
C = C + 1
Next
Next
For i = 0 To UBound(Arr) - 3
For x = i + 1 To UBound(Arr) - 2
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 2)
Brr(C, 1) = "4個相加"
C = C + 1
Next
Next
For i = 0 To UBound(Arr) - 4
For x = i + 1 To UBound(Arr) - 3
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 2) + Arr(x + 3)
Brr(C, 1) = "5個相加"
C = C + 1
Next
Next
[A1].Resize(UBound(Arr) + 1, 1) = Application.Transpose(Arr)
[B1].Resize(UBound(Brr), 2) = Brr
End Sub作者: Andy2483 時間: 2021-9-27 14:07
Option Explicit
Sub TEST_20210928() '
Dim i&, C&, Arr, Brr, x&
Arr = Array(1, 10, 100, 1000, 10000)
ReDim Brr(0 To 1000, 1)
C = 0
For i = 0 To UBound(Arr)
Brr(C, 0) = Arr(i)
Brr(C, 1) = "單一"
C = C + 1
Next
For i = 0 To UBound(Arr)
For x = i + 1 To UBound(Arr)
Brr(C, 0) = Arr(i) + Arr(x)
Brr(C, 1) = "2個相加"
C = C + 1
Next
Next
For i = 0 To UBound(Arr) - 1
For x = i + 1 To UBound(Arr) - 1
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1)
Brr(C, 1) = "3個相加"
C = C + 1
Next
For x = i + 1 To UBound(Arr) - 2
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 2)
Brr(C, 1) = "3個相加"
C = C + 1
Next
For x = i + 1 To UBound(Arr) - 3
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 3)
Brr(C, 1) = "3個相加"
C = C + 1
Next
Next
For i = 0 To UBound(Arr) - 3
For x = i + 1 To UBound(Arr) - 2
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 2)
Brr(C, 1) = "4個相加"
C = C + 1
Next
For x = i + 1 To UBound(Arr) - 3
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 2) + Arr(x + 3)
Brr(C, 1) = "4個相加"
C = C + 1
Next
For x = i + 1 To UBound(Arr) - 3
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 3)
Brr(C, 1) = "4個相加"
C = C + 1
Next
For x = i + 2 To UBound(Arr) - 3
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 2) + Arr(x + 3)
Brr(C, 1) = "4個相加"
C = C + 1
Next
Next
For i = 0 To UBound(Arr) - 4
For x = i + 1 To UBound(Arr) - 3
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 2) + Arr(x + 3)
Brr(C, 1) = "5個相加"
C = C + 1
Next
Next
Workbooks.Add
[A1].Resize(UBound(Arr) + 1, 1) = Application.Transpose(Arr)
[B1].Resize(UBound(Brr), 2) = Brr
End Sub作者: Andy2483 時間: 2021-9-28 16:07
Option Explicit
Sub TEST_20210928_1()
Dim i&, C&, Arr, Brr, x&
Arr = Array(1, 10, 100, 1000, 10000, 100000)
ReDim Brr(0 To 1000, 1)
C = 0
On Error Resume Next
For i = 0 To UBound(Arr)
Brr(C, 0) = Arr(i)
Brr(C, 1) = "單一"
C = C + 1
Next
For i = 0 To UBound(Arr)
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x)
Brr(C, 1) = "2個相加"
C = C + 1
End If
Next
Next
For i = 0 To UBound(Arr)
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 2)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 3)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 4)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 2)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 3)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 4)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 2) + Arr(x + 3)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 2) + Arr(x + 4)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "3個相加"
C = C + 1
End If
Next
Next
For i = 0 To UBound(Arr)
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 2)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 3)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 4)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 2) + Arr(x + 3)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 2) + Arr(x + 4)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 2) + Arr(x + 3)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 2) + Arr(x + 4)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 2) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "4個相加"
C = C + 1
End If
Next
Next
For i = 0 To UBound(Arr)
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 2) + Arr(x + 3)
Brr(C, 1) = "5個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 2) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "5個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "5個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x) + Arr(x + 1) + Arr(x + 2) + Arr(x + 4)
Brr(C, 1) = "5個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 2) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "5個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 2) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "5個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 2) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "5個相加"
C = C + 1
End If
Next
For x = i To UBound(Arr)
If i <> x Then
Brr(C, 0) = Arr(i) + Arr(x + 1) + Arr(x + 2) + Arr(x + 3) + Arr(x + 4)
Brr(C, 1) = "5個相加"
C = C + 1
End If
Next
Next
Brr(C, 0) = Arr(0) + Arr(1) + Arr(2) + Arr(3) + Arr(4) + Arr(5)
Brr(C, 1) = "6個相加"
Workbooks.Add
[A1].Resize(UBound(Arr) + 1, 1) = Application.Transpose(Arr)
[B1].Resize(UBound(Brr), 2) = Brr
[B:B].AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Columns _
("E:E"), Unique:=True
[E:E].Sort _
KEY1:=[E1], Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, SortMethod:=xlStroke, _
DataOption1:=xlSortNormal
End Sub作者: Andy2483 時間: 2021-9-29 11:28
Option Explicit
Sub ListCombination_Add()
Dim Arr, n&, i&, j&, Brr
Arr = Array(1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000#)
n = UBound(Arr) - LBound(Arr) + 1
ReDim Brr(1 To 2 ^ n - 1, 1 To n + 1)
For i = 1 To 2 ^ n - 1
For j = 0 To n - 1
If i And 2 ^ j Then
Brr(i, j + 1) = Arr(j)
Brr(i, n + 1) = Brr(i, n + 1) + Arr(j)
End If
Next
Next
Workbooks.Add
Cells.ClearContents
[A1].Resize(UBound(Brr), UBound(Brr, 2)) = Brr
Cells.Columns.AutoFit
End Sub