本文目录一览

1,excel 随机抽取样本

假定数组在A1:A50 那么在B1 到 B10 、C1到C10 ..... 每个单元格里输入以下公式可以实现随机抽取(可以向下向左拉填充柄) 随机抽取 =INDEX($A$1:$A$50,INT(RAND()*50),1)

excel 随机抽取样本

2,excel随机抽取

按ALT+F11, 将如下代码放到 Thisworkbook 中,回到你的表,按ALT+F8执行Seperate_random 这个宠Public Sub Seperate_random() Dim i As Long Range("C1").FormulaR1C1 = "=RAND()" Range("C1").Select Selection.AutoFill Destination:=Range("C1:C20000") Range("C1:C4").Select Columns("A:C").Select ActiveSheet.Sort.SortFields.Clear ActiveSheet.Sort.SortFields.Add Key:=Range("B:B"), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal ActiveSheet.Sort.SortFields.Add Key:=Range("C:C"), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveSheet.Sort .SetRange Range("A:C") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .apply End With Application.Calculation = xlManual Cells(1, 3) = Cells(1, 3) + 1 For i = 2 To 20000 If Cells(i, 2) <> Cells(i - 1, 2) Then Cells(i, 3) = Cells(i, 3) + 1 Else Cells(i, 3) = Cells(i, 3).Value End If Next i Application.Calculation = xlCalculationAutomatic Columns("A:C").Select ActiveSheet.Sort.SortFields.Clear ActiveSheet.Sort.SortFields.Add Key:=Range("C:C"), _ SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal With ActiveSheet.Sort .SetRange Range("A:C") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End WithEnd Sub处理后前5000的就是你要的随机的.
假定数组在a1:a50那么在b1 到 b10 、c1到c10 .....每个单元格里输入以下公式就可以实现随机抽取(可以向下向左拉填充柄)随机抽取=index($a$1:$a$50,int(rand()*50),1)

excel随机抽取


文章TAG:随机  抽取  excel  抽取样  随机抽取  随机抽取样本  
下一篇