Question : Excel: how can i obtain the cross product of concatenating two columns

I have two columns of text (some are multi word with spaces embedded)

A
B
C
D


1
2
3


how can i get a third column to contain
A1
A2
A3
B1
,,,
D3

(index order doesn't matter   A1, B1, C1, D1, A2, .etc)

thanks

Answer : Excel: how can i obtain the cross product of concatenating two columns

Here is a macro to give all combinations of each cell in two columns of data, putting the results in a third.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
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
Random Solutions  
 
programming4us programming4us