rangequestion
Board Regular
- Joined
- Nov 21, 2016
- Messages
- 62
Hi,
I Have the code below that randomly selects 5% of rows in the active worksheet and pastes it to another. The problem is that this macro delivers duplicate rows. Is there any way to edit the code to ensure duplicates are not in the new worksheet?
Thanks
I Have the code below that randomly selects 5% of rows in the active worksheet and pastes it to another. The problem is that this macro delivers duplicate rows. Is there any way to edit the code to ensure duplicates are not in the new worksheet?
Thanks
Sub RandSelect()
Dim Qty As Long
Dim UsdRws As Long
Dim Rw As Long
Dim MasterSht As Worksheet
Dim NewSht As Worksheet
Set MasterSht = ActiveSheet
UsdRws = Cells.Find("*", after:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Sheets.Add(after:=Sheets(Sheets.Count)).Name = "QC Sample"
Set NewSht = Sheets("QC Sample")
MasterSht.Rows(1).Copy NewSht.Range("A1")
Qty = Int(0.05 * UsdRws)
Do While Qty > 0
Rw = WorksheetFunction.RandBetween(2, UsdRws)
MasterSht.Rows(Rw).Copy NewSht.Range("A" & Rows.Count).End(xlUp).Offset(1)
Qty = Qty - 1
Loop
End Sub
Dim Qty As Long
Dim UsdRws As Long
Dim Rw As Long
Dim MasterSht As Worksheet
Dim NewSht As Worksheet
Set MasterSht = ActiveSheet
UsdRws = Cells.Find("*", after:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Sheets.Add(after:=Sheets(Sheets.Count)).Name = "QC Sample"
Set NewSht = Sheets("QC Sample")
MasterSht.Rows(1).Copy NewSht.Range("A1")
Qty = Int(0.05 * UsdRws)
Do While Qty > 0
Rw = WorksheetFunction.RandBetween(2, UsdRws)
MasterSht.Rows(Rw).Copy NewSht.Range("A" & Rows.Count).End(xlUp).Offset(1)
Qty = Qty - 1
Loop
End Sub