Dim ray(), n, com, comgon, cl As Integer, Vu As Range, oRes
Dim oSt, oNu, oPc, iPc, obit, allnu, c, oVal(), res, oPst, cc
Dim L, oWd As Integer
cl = 1
cc = 1
On Error Resume Next
Set Vu = Application.InputBox( _
Prompt:="Please Select Range with String ", _
Title:="String Combinations", Type:=8)
If Vu Is Nothing Then
MsgBox "No Value Entered"
Exit Sub
End If
L = Vu.Columns.Count
If L > 15 Then
MsgBox "String too Large to Process"
Exit Sub
End If
Range(Cells(2, 1), Cells(50000, L)).ClearContents
oRes = Vu.Value
oNu = Vu.Columns.Count
For n = 1 To oNu
ReDim Preserve ray(n)
ray(n) = n
com = com & n & ","
Next n
comgon = Left(com, Len(com) - 1)
For oPc = 1 To UBound(ray) - 1
obit = ray(oPc)
For iPc = oPc + 1 To UBound(ray)
allnu = obit & "," & ray(iPc)
c = c + 1
cc = cc + 1
ReDim Preserve oVal(c)
oVal(c) = allnu
Next iPc
Next oPc
Do Until allnu = comgon
res = res + 1
obit = oVal(res)
oSt = Split(obit, ",")(UBound(Split(obit, ",")))
For iPc = oSt + 1 To UBound(ray)
allnu = obit & "," & ray(iPc)
c = c + 1
cc = cc + 1
If c = 1000000 Then MsgBox "Limit Reached " & c: Exit Sub
If cc = 50000 Then cc = 1: cl = cl + 1
ReDim Preserve oVal(c)
oVal(c) = allnu
Next iPc
Loop
Dim oCols, oSp, oComb, oAc As Integer, oDn As Integer, Ac
ReDim oComb(1 To c, 1 To oNu)
For oDn = 1 To UBound(oComb, 1)
oSp = Split(oVal(oDn), ",")
For Ac = 0 To UBound(oSp)
Dim Tt
For oWd = 1 To UBound(oRes, 2)
If oWd = Val(oSp(Ac)) Then
oComb(oDn, Ac + 1) = oRes(1, oWd)
End If
Next oWd
Next Ac
Next oDn
Range("A2").Resize(c, oNu).Value = oComb
MsgBox "The Total Number of Combinations is " & c