rand between

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
510
Office Version
  1. 365
Platform
  1. Windows
hi,
i want to generate a random number/s from a list/range c2:h3,
but,
a-i got error of #ref
b-how to i choose the amount of rand numbers returned?
c-is it possible to eliminate duplicates based on the second range? c5:h6
(if in j2 i got 5 i want exclude it in j5)

test
CDEFGHIJ
2123456#REF!
3789101112
4
5123456#REF!
6789101112
test
Cell Formulas
RangeFormula
J2,J5J2=INDEX(C2:H3, RANDBETWEEN(1, 6))
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try:

Dante Amor
CDEFGHIJ
21234568
3789101112
4
51234567
6789101112
Hoja10
Cell Formulas
RangeFormula
J2,J5J2=INDEX(C2:H3, RANDBETWEEN(1,2),RANDBETWEEN(1,6))
 
Upvote 0
Another option
Fluff.xlsm
ABCDEFGHIJ
1
21234562
3789101112
4
51234568
6789101112
Main
Cell Formulas
RangeFormula
J2J2=INDEX(TOCOL(C2:H3,1),RANDBETWEEN(1,2))
J5J5=LET(a,TOCOL(C5:H6,1),INDEX(FILTER(a,a<>J2),RANDBETWEEN(1,11)))
 
Upvote 0
danteamor, it return sometimes the same in j2 and j5,
fluff, it works but in j2 it always return 1 or 2, nothing else

also, how to choose how many numbers returned in the formula?
 
Upvote 0
The 2 in randbetween should be a 12
 
Upvote 0
perfect,
anyway to eliminate duplicates more then one number with your formula here? range maybe? like j2:j5 or k2:n2 ?
Excel Formula:
=LET(a,TOCOL(C5:H6,1),INDEX(FILTER(a,a<>J2),RANDBETWEEN(1,11)))

and regarding the amount of choosing?
 
Upvote 0
How about
Excel Formula:
=LET(a,TOCOL(C5:H6,1),f,FILTER(a,ISNA(MATCH(a,J2:J3,0))),INDEX(a,RANDBETWEEN(1,ROWS(f))))
 
Upvote 0
didn't worked, why?
test
CDEFGHIJKL
2123456771
3789101112
4123456
5789101112
6123456
7789101112
8123456
test
Cell Formulas
RangeFormula
J2J2=INDEX(TOCOL(C3:H4,1),RANDBETWEEN(1,2))
K2K2=LET(a,TOCOL(C5:H6,1),f,FILTER(a,ISNA(MATCH(a,J2:J2,0))),INDEX(a,RANDBETWEEN(1,ROWS(f))))
L2L2=LET(a,TOCOL(C7:H8,1),f,FILTER(a,ISNA(MATCH(a,J2:K2,0))),INDEX(a,RANDBETWEEN(1,ROWS(f))))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
J2:O2Cell ValueduplicatestextNO
 
Upvote 0
It should be
Excel Formula:
=LET(a,TOCOL(C5:H6,1),f,FILTER(a,ISNA(MATCH(a,J2:J2,0))),INDEX(f,RANDBETWEEN(1,ROWS(f))))
 
Upvote 0
Solution

Forum statistics

Threads
1,215,231
Messages
6,123,756
Members
449,120
Latest member
Aa2

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