获取所有可能组合的代码如下
Option Explicit
Sub Combinations()
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
Dim a As Range, b As Range, c As Range, d As Range
Dim x&, y&, z&, w&
For x = 1 To ws.Range("A" & Rows.Count).End(xlUp).Row
Set a = ws.Range("A" & x)
For y = 1 To ws.Range("B" & Rows.Count).End(xlUp).Row
Set b = ws.Range("B" & y)
For z = 1 To ws.Range("C" & Rows.Count).End(xlUp).Row
Set c = Range("C" & z)
For w = 1 To ws.Range("D" & Rows.Count).End(xlUp).Row
Set d = ws.Range("D" & w)
Debug.Print a & vbTab & b & vbTab & c & vbTab & d
Set d = Nothing
Next
Set c = Nothing
Next
Set b = Nothing
Next y
Set a = Nothing
Next x
End Sub
和输出
A 1 F1 R1
A 1 F2 R1
A 1 F3 R1
A 2 F1 R1
A 2 F2 R1
A 2 F3 R1
B 1 F1 R1
B 1 F2 R1
B 1 F3 R1
B 2 F1 R1
B 2 F2 R1
B 2 F3 R1
C 1 F1 R1
C 1 F2 R1
C 1 F3 R1
C 2 F1 R1
C 2 F2 R1
C 2 F3 R1
D 1 F1 R1
D 1 F2 R1
D 1 F3 R1
D 2 F1 R1
D 2 F2 R1
D 2 F3 R1
E 1 F1 R1
E 1 F2 R1
E 1 F3 R1
E 2 F1 R1
E 2 F2 R1
E 2 F3 R1