This question already has an answer here:
这个问题在这里已有答案:
- Unique Random Numbers using VBA 4 answers
使用VBA 4答案的唯一随机数
I'm trying to make a set box of cells populate in a random appearing order. I have it just running through way more iterations than necessary so that the entire box populates. I wish to exclude previous selections to make the process quicker and more fluid. Thank you!
我正试图以随机出现的顺序填充一组单元格。我只是通过比必要更多的迭代运行它,以便整个框填充。我希望排除以前的选择,以使过程更快,更流畅。谢谢!
1 个解决方案
#1
0
I am sure this has millins of anwers. what I will explain you what I would do. then you can paste your code and if you have problems someone can help you.
我相信这里有很多的水壶。我会解释你会做什么的。然后你可以粘贴你的代码,如果你有问题,有人可以帮助你。
I would make a routine that sorts your array randomly, how? add to your array another column where you will place a ramdon number generated by excel. then sort your array according to your random number. I will make an example:
我会做一个例程,随机排序你的数组,怎么样?将另一列添加到您的数组中,您将在其中放置由excel生成的ramdon数字。然后根据随机数对数组进行排序。我会举一个例子:
Original array:
(your int column,Rand column)
(你的int列,Rand列)
(1,0.3212) (2,0.7423) (3,0.0311) (4,0.03144) (5,0.952)
(1,0.3212)(2,0.7423)(3,0.0311)(4,0.03144)(5,0.952)
then if you order it you will get something like this:
然后,如果你订购它,你会得到这样的东西:
5 2 1 4 3
5 2 1 4 3
then all you have to do is return next item in your array and of cource they wil never repeat.
那么你所要做的就是返回数组中的下一个项目和cource,它们将永远不会重复。
I think this is a really fast way.
我认为这是一个非常快的方式。
Hope it helps
希望能帮助到你
#1
0
I am sure this has millins of anwers. what I will explain you what I would do. then you can paste your code and if you have problems someone can help you.
我相信这里有很多的水壶。我会解释你会做什么的。然后你可以粘贴你的代码,如果你有问题,有人可以帮助你。
I would make a routine that sorts your array randomly, how? add to your array another column where you will place a ramdon number generated by excel. then sort your array according to your random number. I will make an example:
我会做一个例程,随机排序你的数组,怎么样?将另一列添加到您的数组中,您将在其中放置由excel生成的ramdon数字。然后根据随机数对数组进行排序。我会举一个例子:
Original array:
(your int column,Rand column)
(你的int列,Rand列)
(1,0.3212) (2,0.7423) (3,0.0311) (4,0.03144) (5,0.952)
(1,0.3212)(2,0.7423)(3,0.0311)(4,0.03144)(5,0.952)
then if you order it you will get something like this:
然后,如果你订购它,你会得到这样的东西:
5 2 1 4 3
5 2 1 4 3
then all you have to do is return next item in your array and of cource they wil never repeat.
那么你所要做的就是返回数组中的下一个项目和cource,它们将永远不会重复。
I think this is a really fast way.
我认为这是一个非常快的方式。
Hope it helps
希望能帮助到你