All Combinations

barim

Board Regular
Joined
Apr 19, 2006
Messages
176
Hello,

I think I've found the right codes for getting all combinations for the characters in the array. My only problem is that it is printing in the message box and telling me that there are 64 combinations. How am I going to print those 64 combinations on the worksheet into one column? I would like to see those combinations.

Any help is appreciated. Thanks.

Code:
Sub ListAllCombinations()
  Dim items(1 To 6) As String
  Dim x As Worksheet
  Dim txt As String
  Dim a As Integer, b As Integer, c As Integer
  Dim d As Integer, e As Integer, f As Integer
  Dim n As Integer
  
' List the names here:
  items(1) = "A"
  items(2) = "B"
  items(3) = "C"
  items(4) = "D"
  items(5) = "E"
  items(6) = "F"
  
  Set x = ThisWorkbook.Sheets.Add
  For a = True To False
    For b = True To False
      For c = True To False
        For d = True To False
          For e = True To False
            For f = True To False
              n = n + 1
              txt = "("
              If a Then txt = txt & items(1) & ", "
              If b Then txt = txt & items(2) & ", "
              If c Then txt = txt & items(3) & ", "
              If d Then txt = txt & items(4) & ", "
              If e Then txt = txt & items(5) & ", "
              If f Then txt = txt & items(6) & ", "
              txt = txt & ")"
              txt = Replace(txt, ", )", ")")
              x.Cells(n, 1).Value = n
              x.Cells(n, 2).Value = txt
            Next f
          Next e
        Next d
      Next c
    Next b
  Next a
  
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
That's exactly what that code does. There is no message in the code, so it cannot be showing you a message box.
 
Upvote 0
That's exactly what that code does. There is no message in the code, so it cannot be showing you a message box.

Sorry I erased this piece. If I could replace this part with printing these values on the worksheet. I don't need message box.
Code:
MsgBox n & " combinations found.", vbInformation
 
Upvote 0
But the code you posted does write the results to a worksheet.
 
Upvote 0

Forum statistics

Threads
1,214,874
Messages
6,122,034
Members
449,061
Latest member
TheRealJoaquin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top