RANDBETWEEN with ascending order

khardu

Board Regular
Joined
Jan 18, 2012
Messages
68
Hello dear excel users,


how can I use RANDBETWEEN to list the result in an ascending order.







Thanking you.




Regards,




KHARDU
 
I would have definitely thought ROWS and COLUMNS as being non-volatile. But correct me if I am wrong, regardless of the content of the cell, ROWS($A$1:A1) would return the row number right?
No, not the row number but the COUNT of rows being referenced.

I mean to say if in A1 to A5 we have volatile formulas such as the ones described in the link you posted, the Row [COUNT] number would still return correctly... no?
Yes

This said, Yes using the first cell in which the target formula is entered as anchor, will definitely make it easier to maintain.

Thanks again, learned something new.
It's all about KISS. ;)
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Aladin Akyurek said:
I have ever introduced and used

ROW()-ROW($C$2)+1

which is volatile because ROW() is volatile.
ROW() is not volatile.

It's easy enough to test.

Open a new file.
Enter this formula in cell B5: =ROW()
Save the file and close it.

Now, open the file. Don't do anything and after a few minutes close the file.

If ROW() was volatile then Excel would have asked you if you wanted to save changes.

What ROW() is, is it's vulnerable to new row insertions. If you have a formula that uses ROW() and the formula is entered in cell B5 then ROW() evaluates to 5. If you insert new rows at or before row 5 then your ROW() function now refers to a different row and returns a different number which may negatively effect your formula.

If you use ROWS(...), it's not vulnerable to this type of row insertion. So, as a general rule we can say that using ROWS(...) is more robust that using ROW().
 
Last edited:
Upvote 0
As a note to this, if you have the Analysis Tool Pack add-in installed you could consider using MRAND()
This will prevent duplication of random numbers in your result.
You also have the option of a static or volatile result.
e.g.
For a volatile result select A2:A31 and put this in the formula bar
Code:
=MRAND(30,0,2099)+1000
Confirm with Ctrl +Shift+Enter not just Enter
You shold now have 30 random numbers from 1000 to 3099 in A2:A31

For a static result use
Code:
=MRAND(30,0,2099,TRUE)+1000

Drag B2:C2 Down to Row #31

Excel Workbook
ABC
1Random NosAscendingDescending
2104310213034
3226810432963
4292211172922
5242011282730
6135611402704
7162713562548
8273013972508
9270414902429
10250815432420
11139715782401
12173715922351
13157816272337
14189816502268
15149017372007
16191118981911
17159219111898
18102120071737
19242922681650
20235123371627
21233723511592
22303424011578
23240124201543
24112824291490
25154325081397
26254825481356
27111727041140
28165027301128
29114029221117
30200729631043
31296330341021
Sheet1
 
Upvote 0
A further note ...

Using MRAND() can also eliminate helper column(s)

e.g.
Select A2:A31

Enter this in the formula bar, with or without ,TRUE
Code:
=SMALL(MRAND(30,0,2099[COLOR=#ff0000],TRUE[/COLOR])+1000,ROW($A$1:$A$30))
Confirm with Ctrl +Shift+Enter not just Enter
You shold now have 30 random numbers from 1000 to 3099 in A2:A31

Similarly with LARGE()
 
Upvote 0
Aladin Akyurek said:
Although I'm sure it's not needed, ROW()-ROW($C$2)+1 and ROWS($C$2:C2) are both robust when used in a formula which is entered in C2. Cyril, I apologize for the repeat.
Kind of expensive using 2 functions plus 2 math operations:

ROW()-ROW($C$2)+1

More efficient to simply use:

ROWS($C$2:C2)
 
Upvote 0
Cyril, I apologize for the repeat.

No need to apologize, precision is what we need and this site is a great tool for all (forum members and guest) to learn the correct syntax and the various alternatives.

Re Mrand, as underlined by Biff, it is not native to Excel (and not available on Mac's version either). This said it looks as well an interesting approach to consider given that the Analysis Tool Pack is indeed installed on your version of Excel. (yes Biff my syntax was off, it does indeed refer to the COUNT of rows...)

KHARDU posted a similar yet different problem on this link. My feeble attempt to come up with a solution raised another limiting factor, If you have the time please have a look as it may certainly gives us all the opportunity to learn from each other.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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