Excel automated random selection

jaz1240

New Member
Joined
Feb 27, 2016
Messages
3
I have table that has repeated timestamps (multiple records within 1 second). there are a variable number of records within each second; ranging from 1 record to 103 records within a second. I wish to develop a method to select only one random record from all the records with the same timestamp.

The Time column is column A. if possible, i would like the end result of the formula(s) (or macro/VBA) to have the word Keep in column B in the row that was randomly selected. all other non selected rows can be left blank.

thanks and i apologize if my example data table is not formatted correctly

[TABLE="width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl63, width: 64"]Time[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:05[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:06[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:07[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:08[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:09[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:10[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:10[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:11[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:11[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:11[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:11[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:11[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:11[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:12[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:12[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:13[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:13[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:13[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:13[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:13[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:13[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:14[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:14[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:15[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:15[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:15[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:15[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:15[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:15[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:16[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:16[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:17[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:17[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:17[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:17[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:17[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:17[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:18[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:18[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:19[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:19[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:19[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:19[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:19[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:19[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:20[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:20[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:21[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:21[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:21[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:21[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:21[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:21[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:22[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:22[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:22[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:22[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
[TR]
[TD="class: xl63"]7:51:23[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Crossposted at: Excel automated random selection

Vba solution for the given problem:
Code:
Option Explicit

Sub RandomPerSecond()
Dim LR As Long, i As Long, rw As Long
Dim CurrTime As Double, MyMax As Double, MyARR As Variant

Application.ScreenUpdating = False
With ActiveSheet
    LR = .Range("A" & .Rows.Count).End(xlUp).Row
    .Range("B2:C" & LR).ClearContents
    .Range("C2:C" & LR).Formula = "=RAND()"
    ReDim MyARR(1 To LR, 1 To 3)
    MyARR = .Range("A1:C" & LR).Value
    CurrTime = MyARR(2, 1)
    For rw = 2 To LR
        If MyARR(rw, 1) = CurrTime Then
            If MyARR(rw, 3) > MyMax Then
                MyMax = MyARR(rw, 3)
                i = rw
            End If
        Else
            MyARR(i, 2) = "Keep"
            i = rw
            MyMax = 0
            CurrTime = MyARR(rw, 1)
            MyMax = MyARR(rw, 3)
        End If
        If rw = LR Then
            MyARR(i, 2) = "Keep"
            Exit For
        End If
    Next rw
    .Range("A1:C" & LR).Value = MyARR
    .Range("C2:C" & LR).ClearContents
End With
Application.ScreenUpdating = True
Beep
End Sub
 
Upvote 0
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule #13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top