excel - Trying to find all possible combinations -


i have been trying work through following problem using excel , not sure start, have tried using combinations , permeation have basic understanding of them, how guys approach solving this?

there 6 kinds of coffee , there 10 kinds of flavor shots , can put one, 2 or 3 shots in each kind of coffee. based on this, know (and list) unique flavor combinations , how long go without having same cup of coffee.

very simple macros.

the first thing note need combinations rather permutations. because {kona,vanella,chocolate} same {kona,chocolate,vanilla}.

place 6 coffee a1 thru a6

place 10 flavors in b2 thru b11. leave b1 empty.

enter , run following vba macro:

sub coffeemixer()     dim k long, _         long, _         j long, _         l long, _         z long     z = 1     = 1 10         cf = cells(i, 1).value         j = 1 11             fl1 = cells(i, 2).value             k = j+1 11                 fl2 = cells(k, 2).value                 l = k+1 11                     fl3 = cells(l, 2).value                     if fl1 = fl2 or fl1 = fl3 or fl2 = fl3                     else                         cells(z, "c").value = cf                         cells(z, "d").value = fl1                         cells(z, "e").value = fl2                         cells(z, "f").value = fl3                         z = z + 1                     end if                 next l             next k         next j     next end sub 

this produce 875 samples.

macros easy install , use:

  1. alt-f11 brings vbe window
  2. alt-i alt-m opens fresh module
  3. paste stuff in , close vbe window

if save workbook, macro saved it. if using version of excel later 2003, must save file .xlsm rather .xlsx

to remove macro:

  1. bring vbe window above
  2. clear code out
  3. close vbe window

to use macro excel:

  1. alt-f8
  2. select macro
  3. touch run

to learn more macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

macros must enabled work!

here sample:

xx

.

.

edit#1

here updated code:

sub coffeemixer()     range("c:f").clear     dim k long, _         long, _         j long, _         l long, _         z long     z = 1     = 1 6         cf = cells(i, 1).value         j = 1 11             fl1 = cells(j, 2).value             kk = j + 1             if j = 11 kk = 11             k = kk 11                 fl2 = cells(k, 2).value                 ll = 1 + k                 if k = 11 ll = 11                 l = ll 11                     fl3 = cells(l, 2).value                         cells(z, "c").value = cf                         cells(z, "d").value = fl1                         cells(z, "e").value = fl2                         cells(z, "f").value = fl3                         z = z + 1                 next l             next k         next j     next end sub 

using version, must fill b1 thru b10 , leave b11 blank!


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -