我有两张表格,Sheet1有一堆信息,有4个空列,而Sheet2有4个列表,每列都有一堆内容。 示例:
清单1:A,B,C
清单2:D,E,F,G
List3:H,I,J,K,L,M
清单4:N
我想用Sheet1的所有组合填充Sheet1中的空列,并为生成的每个组合复制原始Sheet1内容。 示例:(只是一般性的想法,没有特定的顺序)
ContentXYZ |(空)|(空)|(空)|(空)
ContentXYZ | A |(空)|(空)|(空)
ContentXYZ | B |(空)|(空)|(空)
...
ContentXYZ |(空)| d |(空)|(空)
...
ContentXYZ |(空)|(空)|(空)| N
...
ContentXYZ | B | F |(空)|(空)
...
ContentXYZ |(空)| G |(空)| N
...
ContentXYZ |(空)|电子| K | N
...
ContentXYZ | C | G | M | N
我已经完成了复制部分,并且我被困在组合部分。这是我到目前为止所做的事情,如果有人能帮助我完成剩下的工作,请提前感谢!
Sub DupSubGroup()
b = 1
d = 1
f = 1
h = 1
Do
Sheets(1).Activate
Sheets(1).Range("A1:F1").Copy
erow = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Sheets(1).Rows(erow)
...
Loop While b <= Sheet2.Columns("B:B").SpecialCells(xlVisible).Rows.Count And d <= Sheet2.Columns("D:D").SpecialCells(xlVisible).Rows.Count And f <= Sheet2.Columns("F:F").SpecialCells(xlVisible).Rows.Count And h <= Sheet2.Columns("H:H").SpecialCells(xlVisible).Rows.Count
答案 0 :(得分:0)
如果您正在寻找一个创建所有排列的循环,这是一个例子:
Sub Test()
Dim List1 As Variant, List2 As Variant, List3 As Variant
List1 = Array("A", "B", "C", "D")
List2 = Array(1, 2, 3)
List3 = Array(True, False)
Dim I1 As Integer, I2 As Integer, I3 As Integer, R As Integer
R = 1
For I1 = 0 To UBound(List1)
For I2 = 0 To UBound(List2)
For I3 = 0 To UBound(List3)
Cells(R, 1) = List1(I1)
Cells(R, 2) = List2(I2)
Cells(R, 3) = List3(I3)
R = R + 1
Next I3
Next I2
Next I1
End Sub