我的表有重复的时间戳(1秒内有多个记录)。每秒内有可变数量的记录;一秒钟内从1条记录到103条记录。我希望开发一种方法,从具有相同时间戳的所有记录中仅选择一个随机记录。
时间列是A列。如果可能,我希望公式(或宏/ VBA)的最终结果在随机选择的行中的B列中保留单词Keep。所有其他非随机选择的行可以留空。
谢谢,如果我的示例数据表格式不正确,我深表歉意。
Time
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:05
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:06
7:51:07
7:51:07
7:51:07
7:51:07
7:51:07
7:51:07
7:51:07
7:51:07
7:51:07
7:51:07
7:51:07
7:51:07
7:51:07
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:08
7:51:09
7:51:09
7:51:09
7:51:09
7:51:09
7:51:09
7:51:09
7:51:09
7:51:09
7:51:09
7:51:09
7:51:09
7:51:10
7:51:10
7:51:11
7:51:11
7:51:11
7:51:11
7:51:11
7:51:11
7:51:12
7:51:12
7:51:13
7:51:13
7:51:13
7:51:13
7:51:13
7:51:13
7:51:14
7:51:14
7:51:15
7:51:15
7:51:15
7:51:15
7:51:15
7:51:15
7:51:16
7:51:16
7:51:17
7:51:17
7:51:17
7:51:17
7:51:17
7:51:17
7:51:18
7:51:18
7:51:19
7:51:19
7:51:19
7:51:19
7:51:19
7:51:19
7:51:20
7:51:20
7:51:21
7:51:21
7:51:21
7:51:21
7:51:21
7:51:21
7:51:22
7:51:22
7:51:22
7:51:22
7:51:23
7:51:23
7:51:23
7:51:23
7:51:23
7:51:23
7:51:23
7:51:23
7:51:23
7:51:23
答案 0 :(得分:1)
假设值将被排序,下面的代码应该有效。您应该单步执行代码以确保它按预期工作,一旦删除,请删除.select语句。我只是简单地测试过,所以我留给你进行更彻底的测试。您可以点击此链接成为familiar with the RND function。
Option Explicit
Sub randChoice()
Dim stRow As Long, endRow As Long, t As Integer
stRow = 2
endRow = stRow + 1
While Cells(endRow, 1) <> ""
Do
Cells(endRow, 1).Select
If Cells(stRow, 1) <> Cells(endRow, 1) Then Exit Do
endRow = endRow + 1
Loop
Randomize
t = Int((endRow - stRow) * rnd)
Cells(stRow + t, 2) = "Keep"
stRow = endRow
endRow = stRow + 1
Wend
End Sub