'各位大神,有8000多个人员数据,分布在800多个网格,现在需要在其中随机抽取1000人,但需要保证每个网格至少抽到一人,该如何实现,跪谢跪谢!
Sub chansheng()
Cells(1, "A") = "序号"
Cells(1, "B") = "姓名"
Cells(1, "C") = "网格号"
Cells(1, "D") = "是否抽取"
For i = 1 To 8000
Cells(i + 1, "A") = i
Cells(i + 1, "b") = "姓名" & CStr(i)
Cells(i + 1, "C") = Int(((i - 1) / 10)) + 1
Next i
End Sub
Sub suijichouqu1000()
[d2:d65535].ClearContents
n = [c65535].End(xlUp).Row
maxwangge = CInt(Cells(n, "C"))
For i = 1 To maxwangge
For j = 1 To n
If Cells(j, "C") = i Then Exit For
Next j
kaishi1 = j
For j = kaishi1 To n
If Cells(j, "C") <> i Then Exit For
Next j
jieshu1 = j - 1
bianhao = Application.RandBetween(kaishi1, jieshu1)
Cells(bianhao, "D") = 1
k = k + 1
Next i
For i = k + 1 To 1000
oncemore: bianhao = Application.RandBetween(2, n)
If Cells(bianhao, "D") <> 1 Then
Cells(bianhao, "D") = 1
k = k + 1
Else
GoTo oncemore
End If
Next i
End Sub