Random numbers - an added twist

secondtry

New Member
Joined
Oct 10, 2006
Messages
32
I previously received the following formula from pgc to give me a column of random numbers from 1 to 99 without duplicates and it worked great:

SMALL(IF(COUNTIF($A$1:A1,ROW($1:$99))<>1,ROW($1:$99)),1+INT(RAND()*(99-ROW()+ROW($B$2))))
Holding CTRL+SHIFT+ENTER since it is an array

After putting it to use I began to wonder if it could be tweaked so that the random number would only appear if the cell to the right was not blank. I haven't been able to make anything work. Any ideas?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
Try this in A2 copied down, should give a blank if cell to the right (in column B) is blank

=IF(B2="",SMALL(IF(COUNTIF($A$1:A1,ROW($1:$99))<>1,ROW($1:$99)),1+INT(RAND()*(99-ROW()+COUNTIF($A$1:A1,"")+ROW($A$2)))),"")

confirmed with CTRL+SHIFT+ENTER

note: A1 should not be blank
 

secondtry

New Member
Joined
Oct 10, 2006
Messages
32
That worked like a charm. Within the formula, can I also change the range of random numbers that I want to appear? That is to say, if I want to apply the same formula but have the option of altering the range of numbers anywhere between 1 and 99, what can I do? When I tried replacing the "99" as demonstrated below, I still had random numbers of greater than the chosen variable appearing.

Original formula:
IF(C5="","",SMALL(IF(COUNTIF($B$4:B4,ROW($4:$102))<>1,ROW($4:$102)),1+INT(RAND()*(99-ROW()+COUNTIF($B$4:B4,"")+ROW($B$5)))))
 

Forum statistics

Threads
1,136,649
Messages
5,676,989
Members
419,667
Latest member
MegEri

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
Top