Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Excel VBA从包含空列的多个列表生成组合_Excel_Combinations_Vba - Fatal编程技术网

使用Excel VBA从包含空列的多个列表生成组合

使用Excel VBA从包含空列的多个列表生成组合,excel,combinations,vba,Excel,Combinations,Vba,我有两张纸,Sheet1有一堆信息,有4个空栏,Sheet2有4个列表,每个列表下有一堆内容。 例如: 清单1:A、B、C 清单2:D、E、F、G 列表3:H,I,J,K,L,M 清单4:N 我想用列表的所有组合填写Sheet1中的空列,并为生成的每个组合复制原始Sheet1内容。 示例:(只是一个大概的想法,没有特定的顺序) ContentXYZ |(空)|(空)|(空)|(空) ContentXYZ | A |(空)|(空)|(空) ContentXYZ | B |(空)|(空)|(空) …

我有两张纸,Sheet1有一堆信息,有4个空栏,Sheet2有4个列表,每个列表下有一堆内容。 例如:

清单1:A、B、C
清单2:D、E、F、G
列表3:H,I,J,K,L,M
清单4:N

我想用列表的所有组合填写Sheet1中的空列,并为生成的每个组合复制原始Sheet1内容。 示例:(只是一个大概的想法,没有特定的顺序)

ContentXYZ |(空)|(空)|(空)|(空)
ContentXYZ | A |(空)|(空)|(空)
ContentXYZ | B |(空)|(空)|(空)

ContentXYZ |(空)| D |(空)|(空)

ContentXYZ |(空)|(空)|(空)| N

ContentXYZ | B | F |(空)|(空)

ContentXYZ |(空)| G |(空)| N

ContentXYZ |(空)| E | 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
子组()
b=1
d=1
f=1
h=1
做
第(1)页。激活
第(1)页。范围(“A1:F1”)。副本
erow=Sheets(1).单元格(Rows.Count,1).结束(xlUp).偏移量(1,0).行
ActiveSheet.Paste目标:=工作表(1).行(erow)
...

循环While b如果您正在寻找创建所有排列的循环,这里是一个示例:

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