Sub UniqueCombinations()
Dim i As Long, j As Long, k As Long, nRows As Long, nCols As Long
Dim rgDest As Range, rg1 As Range, rg2 As Range
Dim v() As Variant, v1 As Variant, v2 As Variant
Application.ScreenUpdating = False
With Worksheets("Sheet1")
Set rg1 = .Range("A2") 'First cell in first column
Set rg1 = Range(rg1, .Cells(Rows.Count, rg1.Column).End(xlUp)) 'All data in that column
v1 = rg1.Value
End With
With Worksheets("Sheet1")
Set rg2 = .Range("B2") 'First cell in second column
Set rg2 = Range(rg2, .Cells(Rows.Count, rg2.Column).End(xlUp)) 'All data in that column
v2 = rg2.Value
End With
nRows = rg1.Rows.Count
nCols = rg2.Rows.Count
ReDim v(1 To nRows * nCols, 1 To 1)
For i = 1 To nRows
For j = 1 To nCols
k = k + 1
v(k, 1) = v1(i, 1) & v2(j, 1)
Next
Next
With Worksheets("Sheet1")
Set rgDest = .Range("C2") 'Top left cell of destination for combinations
rgDest.Resize(nRows * nCols).Value = v
End With
Application.ScreenUpdating = True
End Sub
|