Random select 3 values per row from specific range without duplicates

wjeil

New Member
Joined
Feb 25, 2022
Messages
37
Office Version
  1. 365
Platform
  1. Windows
Hello,

Im trying to randomly assign products to a certain location randomly. Locations consist of 3 products and are either for an A, B or C product. Therefore it is not possible to have any duplictates. How can I randomly assign products to a certain location so that every product is stored and that there are not any duplicates?

Is there a solutions, VBA or just with formulas, to model this in Excel?

Regards,
Willem
 

Attachments

  • Check.PNG
    Check.PNG
    38.5 KB · Views: 16

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
for the A-products, a named range "Mijn_A" and then as many randum values as products A, rank them and assign them
Map1
ABCDEF
1A120,83439A12A1A3
2A240,82160A2A4A5
3A330,82590A10A8A9
4A450,77260A11A7A6
5A560,65756
6A6120,06282
7A7110,24176
8A880,48688
9A990,44886
10A1070,60733
11A11100,31605
12A1210,91870
Blad2
Cell Formulas
RangeFormula
C1:C12C1=RANDARRAY(ROWS(Mijn_A))
D1:F4D1=INDEX(Mijn_A,MATCH(SEQUENCE(4,3),OFFSET(Mijn_A,,1,,),0))
B1:B12B1=RANK(C1,OFFSET($C$1,,,ROWS(Mijn_A),))
Dynamic array formulas.
Named Ranges
NameRefers ToCells
Mijn_A=Blad2!$A$1:$A$12B1:B12, C1:D1
 
Upvote 0
Another option
+Fluff 1.xlsm
ABCDEFGHIJK
1A1B1C1
2A2B2C2Loc1AA8A3A4
3A3B3C3Loc2AA10A12A6
4A4B4C4Loc3AA2A7A9
5A5B5C5Loc4BA1A5A11
6A6B6C6Loc5BB2B5B18
7A7B7C7Loc6BB7B12B8
8A8B8C8Loc7BB4B17B6
9A9B9C9Loc8BB9B3B13
10A10B10C10Loc9BB14B11B1
11A11B11C11Loc10BB16B15B10
12A12B12C12Loc11CC9C4C3
13B13C13Loc12CC5C21C23
14B14C14Loc13CC7C16C6
15B15C15Loc14CC18C20C19
16B16C16Loc15CC17C10C2
17B17C17Loc16CC24C15C13
18B18C18Loc17CC12C11C8
19C19Loc18CC14C22C1
20C20
21C21
22C22
23C23
24C24
25
Primary
Cell Formulas
RangeFormula
I2:K19I2=LET(a,SORTBY(A1:A12,RANDARRAY(12)),b,SORTBY(B1:B18,RANDARRAY(18)),c,SORTBY(C1:C24,RANDARRAY(24)),ra,ROWS(a),rb,ROWS(b),rc,ROWS(c),s,SEQUENCE((ra+rb+rc)/3,,,3),IF(s<=ra,INDEX(a,s+{0,1,2}),IF(s<=ra+rb,INDEX(b,(s-ra)+{0,1,2}),INDEX(c,s-ra-rb+{0,1,2}))))
Dynamic array formulas.
 
Upvote 0
Another option, slightly longer, but easier to maintain & deals with blank cells if there are no enough products.
+Fluff 1.xlsm
ABCDGHIJKLMNOPQR
1A1B1C1Product 1Product 2Product 3Product 1Product 2Product 3Product 4
2A2B2C2Loc1AA11A7A4Loc1AA3A4A5A9
3A3B3C3Loc2AA8A1A2Loc2AA1A10A12A7
4A4B4C4Loc3AA12A10A9Loc3AA2A6A8A11
5A5B5C5Loc4BA5A3A6Loc4BB12B14B10B6
6A6B6C6Loc5BB7B11B18Loc5BB18B17B2B1
7A7B7C7Loc6BB12B15B1Loc6BB9B3B11B7
8A8B8C8Loc7BB4B10B17Loc7BB16B5B8B15
9A9B9C9Loc8BB14B5B13Loc8BB13B4
10A10B10C10Loc9BB16B6B9Loc9CC15C18C13C5
11A11B11C11Loc10BB8B3B2Loc10CC24C22C23C16
12A12B12C12Loc11CC17C9C12Loc11CC2C20C14C17
13B13C13Loc12CC18C11C2Loc12CC7C11C8C4
14B14C14Loc13CC19C10C16Loc13CC3C1C10C6
15B15C15Loc14CC22C21C4
16B16C16Loc15CC3C24C23
17B17C17Loc16CC7C8C1
18B18C18Loc17CC15C6C13
19C19Loc18CC5C14C20
20C20
21C21
22C22
23C23
24C24
25
Primary
Cell Formulas
RangeFormula
I2:K19I2=LET(a,A1:A12,b,B1:B18,c,C1:C24,Prod,3,ra,ROWS(a),rb,ROWS(b),rc,ROWS(c),sProd,SEQUENCE(,Prod,0),s,SEQUENCE((ra+rb+rc)/Prod,,,Prod),IFERROR(IF(s<=ra,INDEX(SORTBY(a,RANDARRAY(ra)),s+sProd),IF(s<=ra+rb,INDEX(SORTBY(b,RANDARRAY(rb)),(s-ra)+sProd),INDEX(SORTBY(c,RANDARRAY(rc)),s-ra-rb+sProd))),""))
O2:R14O2=LET(a,A1:A12,b,B1:B18,c,C1:C24,Prod,4,ra,ROWS(a),rb,ROWS(b),rc,ROWS(c),sProd,SEQUENCE(,Prod,0),s,SEQUENCE((ra+rb+rc)/Prod,,,Prod),IFERROR(IF(s<=ra,INDEX(SORTBY(a,RANDARRAY(ra)),s+sProd),IF(s<=ra+rb,INDEX(SORTBY(b,RANDARRAY(rb)),(s-ra)+sProd),INDEX(SORTBY(c,RANDARRAY(rc)),s-ra-rb+sProd))),""))
Dynamic array formulas.
 
Upvote 0
It works like a charm thank you very much. I got 1 further question. How can adapt the line so that the first 3 locations randomly contain A1 till A12?
 
Upvote 0
Which formula are you talking about?
 
Upvote 0
In that case I don't understand what you are asking. The formula picks random cells from A1:A12 & fills them in the output without duplicates.
 
Upvote 0
Sorry if i'm unclear. What i was actually trying to say was how can i make this range dynamic? So if I have X A-products, X B products and X C-products, with each corresponding (e.g. if i have 20 A-products I have 7 locations available) locations. How can i make the range which is now A1:A12, B1:B18 and C:C24 towards A1:AX, B1:BX and C1:CX?

So with the assumption that i have enough locations for each product.

Next to that, in my model if SEQUENCE((ra+rb+rc)/Prod,,,Prod) is not an integer it rounds down instead of up.

Thanks for all your help in advance.
 
Upvote 0
Are the values in cols A, B & C spilled ranges?
 
Upvote 0

Forum statistics

Threads
1,214,818
Messages
6,121,725
Members
449,049
Latest member
MiguekHeka

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