/ / Gerar combinações de listas múltiplas, incluindo colunas nulas usando Excel VBA - excel-vba, combinações, vba, excel

Gere combinações de várias listas, incluindo colunas nulas usando o Excel VBA - excel-vba, combinações, vba, excel

Eu tenho duas planilhas, a Planilha1 tem um monte de informações com 4 colunas vazias e a Planilha2 tem 4 listas com um monte de conteúdo em cada uma. Exemplo:

Lista 1: A, B, C
Lista 2: D, E, F, G
Lista 3: H, I, J, K, L, M
Lista 4: N

Eu gostaria de preencher as colunas vazias emFolha1 com todas as combinações das listas e duplique o conteúdo original da Folha1 para cada combinação gerada. Exemplo: (apenas uma ideia geral, sem ordem específica)

ContentXYZ | (vazio) | (vazio) | (vazio) | (vazio)
ContentXYZ | A | (vazio) | (vazio) | (vazio)
ContentXYZ | B | (vazio) | (vazio) | (vazio)
...
ContentXYZ | (vazio) | D | (vazio) | (vazio)
...
ContentXYZ | (vazio) | (vazio) | (vazio) | N
...
ContentXYZ | B | F | (vazio) | (vazio)
...
ContentXYZ | (vazio) | G | (vazio) | N
...
ContentXYZ | (vazio) | E | K | N
...
ContentXYZ | C | G | M | N

Eu fiz a parte da duplicação e estou preso na parte das combinações. Aqui está o que eu fiz até agora, agradeço antecipadamente se alguém puder me ajudar a completar o resto!

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

Respostas:

0 para resposta № 1

Se você está procurando um ciclo que cria todas as permutações, aqui está um exemplo:

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