VBA how much permutation can be made using 3-digit with 0, 1 & 2

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Hello,</SPAN></SPAN>


I want to know is there any formula, which can count permutation can be made using 3-digit with 0, 1 & 2 </SPAN></SPAN>

And a VBA, which can make all possible permutation, using 3-digit with 0, 1 & 2 using 7 cells with in the row which row sum must be = 7</SPAN></SPAN>

Few examples...</SPAN></SPAN>


Book1
EFGHIJKL
1
2
3n1n2n3n4n5n6n7Sum
400121127
512210107
601111127
710112117
810211117
901121117
1011200127
1121110117
1221001127
1311011217
1401210127
1511121017
1621001127
1711111117
1820121017
1911112017
2011121017
2112012017
2201211117
2310012127
2410102127
2512101207
2611201117
2710012127
2820120027
2902102207
3011010227
3110220027
3200122117
3311011127
3421111107
3510111217
3610121207
3701121117
3812011117
3921011117
4012201107
4111011217
4200022217
4312110117
4410122107
4511012117
4611121107
4712002117
4810201217
4911101217
5010111217
5101212107
5211102117
5311120117
5421011117
5502102027
5611002127
5701211207
5801012217
5911020217
6021110117
6120210117
6201201127
6310121117
6411021117
6511102027
Sheet1



Thank you all</SPAN></SPAN>

Excel 2000</SPAN></SPAN>
Regards,</SPAN></SPAN>
Moti</SPAN></SPAN>
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
this code will generate all possible permutations:

Code:
Sub test()
indi = 4
inarr = Range(Cells(4, 5), Cells(4, 11))
For i1 = 0 To 2
 For i2 = 0 To 2
  For i3 = 0 To 2
    For i4 = 0 To 2
     For i5 = 0 To 2
      For i6 = 0 To 2
       For i7 = 0 To 2
        tt = i1 + i2 + i3 + i4 + i5 + i6 + i7
         If tt = 7 Then
          inarr(1, 1) = i1
          inarr(1, 2) = i2
          inarr(1, 3) = i3
          inarr(1, 4) = i4
          inarr(1, 5) = i5
          inarr(1, 6) = i6
          inarr(1, 7) = i7
          Range(Cells(indi, 5), Cells(indi, 11)) = inarr
          indi = indi + 1
         End If
        Next i7
       Next i6
      Next i5
     Next i4
    Next i3
   Next i2
  Next i1
  


End Sub
 
Upvote 0
this code will generate all possible permutations:

Code:
Sub test()
indi = 4
inarr = Range(Cells(4, 5), Cells(4, 11))
For i1 = 0 To 2
 For i2 = 0 To 2
  For i3 = 0 To 2
    For i4 = 0 To 2
     For i5 = 0 To 2
      For i6 = 0 To 2
       For i7 = 0 To 2
        tt = i1 + i2 + i3 + i4 + i5 + i6 + i7
         If tt = 7 Then
          inarr(1, 1) = i1
          inarr(1, 2) = i2
          inarr(1, 3) = i3
          inarr(1, 4) = i4
          inarr(1, 5) = i5
          inarr(1, 6) = i6
          inarr(1, 7) = i7
          Range(Cells(indi, 5), Cells(indi, 11)) = inarr
          indi = indi + 1
         End If
        Next i7
       Next i6
      Next i5
     Next i4
    Next i3
   Next i2
  Next i1
  


End Sub
Wow!! offthelip, code generated 393 permutations this is what I were looking for worked perfect!! (y) </SPAN></SPAN>

Thank you very much, I do appreciate your help and time and for giving a nice solution
</SPAN></SPAN>

Good luck to you
</SPAN></SPAN>

Regards,
</SPAN></SPAN>
Moti :)
</SPAN></SPAN>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,564
Messages
6,125,575
Members
449,237
Latest member
Chase S

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