vba Excel 从具有多个条目的列表中随机选择名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18859508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 23:22:58  来源:igfitidea点击:

Excel randomly select name from list with multiple entries

excelvbaexcel-vbarandom

提问by mriley

I have an excel 2007 worksheet with employee names in column A and total number of entries in column B. I need to be able to randomly select x number of employee names from the total number of entries, allowing for the fact that some will have multiple entries.

我有一个 excel 2007 工作表,A 列中有员工姓名,B 列中有条目总数。我需要能够从条目总数中随机选择 x 个员工姓名,允许某些人有多个条目。

For example:

例如:

Amy............30   
Brian..........12
Charlene.......15
Michael.........1
Nathan..........7

What is the best way to do this?

做这个的最好方式是什么?

My initial thoughts are:

我最初的想法是:

1) find the max() of column B occurances of a random number in another column, like C. Then find the top values for all of that new column.

1) 在另一列中找到随机数在 B 列中出现的 max(),例如 C。然后找到所有新列的最高值。

2) create a VBA array of all of the potiential entries and randomly pick one from there.

2)创建一个包含所有潜在条目的 VBA 数组,并从那里随机选择一个。

3) loop through all of the names in column A and create a temp worksheet with column B instances of each, then assign a random num generator and choose the top n.

3)循环遍历A列中的所有名称并创建一个临时工作表,其中包含每个B列的实例,然后分配一个随机数生成器并选择前n个。

Having said that, there may be something a lot easier. I am not sure where to begin. Normally I can find code that is similar to what I need, but I am not having any luck. Any help that you can offer would be appreciated.

话虽如此,可能会有更容易的事情。我不知道从哪里开始。通常我可以找到与我需要的代码类似的代码,但我没有任何运气。您能提供的任何帮助将不胜感激。

Thank you in advance.

先感谢您。

回答by Stepan1010

I would probably do something like this if I understand your question correctly(I just read your question title):

如果我正确理解您的问题,我可能会做这样的事情(我只是阅读了您的问题标题):

SO1

SO1

SO2

二氧化硫