Hi,

I have a data set as the following

ID ID2 String String2
1234 33423,43222,442224,213432 Sample; repeat; example; multiple second; possible; delimiter
2345 12354; 55633; 343534; 65443;121121 data;set; sample; find answer; combination; by




Now I want to find a Cartesian product of the following data set resulting in a data set with the same column headers but every possible combination of 1-4 columns from the next line of the headers

I have the following code which I was using to resolve the above problem. However, I could only perform Cartesian product for one row at a time. I am a newbie in vba and I tried all possible ways which I can think of to put the below code in a for loop but wasn't successful. Can anyone help me resolve this?

Sub Cartesian()
Dim MyStr1 As Variant, MyStr2 As Variant, MyStr3 As Variant, MyStr4 As Variant, Str1 As Variant, Str2 As Variant, Str3 As Variant, Str4 As Variant, X As Long
MyStr1 = Split(Range("A2").Text, ";")
MyStr2 = Split(Range("B2").Text, ";")
MyStr3 = Split(Range("C2").Text, ";")
MyStr4 = Split(Range("D2").Text, ";")
X = 2
For Each Str1 In MyStr1
    For Each Str2 In MyStr2
        For Each Str3 In MyStr3
            For Each Str4 In MyStr4
                Worksheets("Sheet6").Range("A" & X).Formula = Str1
                Worksheets("Sheet6").Range("B" & X).Formula = Str2
                Worksheets("Sheet6"). Range("C" & X).Formula = Str3
                Worksheets("Sheet6").Range("D" & X).Formula = Str4
                X = X + 1
            Next
        Next
    Next
Next
End Sub

Or is there a way I could achieve this using SQL within excel?