Tuesday, March 15, 2011

Solved: determine all combinations in a string [Archive] - VBA Express Forum

I chalk up 4 letters (a,b,c,d) that can be combined in a limit

I'm trying to construct a service/sub that lists all the colorful combinations of the 4 letters such as:

2. aa, ab, ac, ad, ba, bb, bc, bd, ca, cb, cc, disc, da, db, dc, dd

3. aaa, aab, aac, abc, bac, ddd, ...

I worked on it a while and my attitude is going delirious. Any ideas?

:banghead:

' Disclose: I can't bethink who is the orginal regulation writter

N = Practice.WorksheetFunction.Combin(PopSize, SetSize)

N = Manipulate.WorksheetFunction.Permut(PopSize, SetSize)

vAllItems = Rng.Offset(2, 0).Resize(PopSize).Value

DataError:

Which = "Enter your info in a vertical area of at least 4 cells. " _

& "Top cell must include the packages C or P, 2nd cell is the symbol " _

& "of items in a subset, the cells below are the values from which " _

Which = "This requires " & Format$(N, "#,##0") & _

" cells, extended than are available on the worksheet!"

Private Sub AddPermutation(Optional PopSize As Integer = 0, _

Private Sub AddCombination(Optional PopSize As Integer = 0, _

Private Sub SavePermutation(ItemsChosen() As Integer, _

Provided FlushBuffer = Exactly Or BufferPtr = UBound(Buffer()) Then

Results.Cells(RowNum, ColNum).Resize(BufferPtr, 1).Value _

= Manipulate.WorksheetFunction.Transpose(Buffer())

sValue = sValue & ", " & vAllItems(ItemsChosen(i), 1)

Example:


No comments:

Post a Comment