So i have a VBA script that I'm using to generate all possible combinations using 4 columns of data. The output is needing to be formatted a certain way as well. Currently this is what I have:
Option Explicit
Sub Sample()
Dim i As Long, j As Long, k As Long, l As Long
Dim CountComb As Long, lastrow As Long
Range("G2").Value = Now
Application.ScreenUpdating = False
CountComb = 0: lastrow = 6
For i = 1 To 15: For j = 1 To 23
For k = 1 To 9: For l = 1 To 11
Range("G" & lastrow).Value = "key=" & Range("A" & i).Value & "&details=" & _
Range("B" & j).Value & "/" & _
Range("C" & k).Value & "/" & _
Range("D" & l).Value
lastrow = lastrow + 1
CountComb = CountComb + 1
Next: Next
Next: Next
Range("G1").Value = CountComb
Range("G3").Value = Now
Application.ScreenUpdating = True
End Sub
It does indeed work to a certain extent, however the issues are that it only seems to return combinations of all 4 columns, when I'd like for it to return combinations using 1-3 columns as well. Essentially like this:
key=1&details=2
key=1&details=2/3
key=1&details=2/3/4
key=1&details=2/3/4/5
Also, I somehow was able to get 1/2/3 to work, however it keeps adding a / on the end if the combination uses less than all 4 columns which is messing up what I'm using it for. How would I go about generating the combinations without a trailing / ? Any help with this would be greatly appreciated, I've been stuck on it for hours. Thanks!
Bookmarks