If my input is 1, 2 & 3 then result should be 1,2,3,12,13,23,123
Input can go up to 20 digits also
Also, result 12 and 21 should treat as same
Similarly, 123 & 321 or 231 or 312 is the same.
here is the perfect dynamic solution. You can add more than 20 digits and it will still provide you with the perfect result.
Put the following code in the module and that's it. I was working on this since yesterday. :D
Sub Perform_Combination_Series_Dynamic()
Dim InputString, MainString, PartS As String
Dim I, J, K, L, M, Group As Long
Dim InputStringDigits() As String 'Array
InputString = Application.InputBox("Please Enter a digits seperated by comma")
InputStringDigits = VBA.Split(InputString, ",")
MainString = vbNullString
I = UBound(InputStringDigits) - LBound(InputStringDigits) + 1
For J = 1 To I Step 1
MainString = MainString & "," & J
Next J
For Group = 0 To I - 2
For J = 1 To I
For K = J + 1 To I
If K + Group <= I Then
PartS = vbNullString
For M = 0 To Group
PartS = PartS & K + M
Next M
MainString = MainString & "," & J & PartS
End If
Next K
Next J
Next Group
MsgBox VBA.Mid(MainString, 2, VBA.Len(MainString))
End Sub
No comments:
Post a Comment