sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,421
- Office Version
- 2016
- Platform
- Windows
Hi Guys,
I'm trying to find a way using VBA to copy a specified number of random rows from a filtered range.
I've scrambled this together so far
It works, sort of - it copies the correct amount of random cells but not from the visible range.
Could someone help me understand why, or indeed provide a far better solution?
I'm trying to find a way using VBA to copy a specified number of random rows from a filtered range.
I've scrambled this together so far
VBA Code:
LastNumber = WorksheetFunction.Subtotal(103, wb.Sheets(2).Range("A2:A5000"))
NumberToImport = ComboRecords.Value
MaxNumber = LastNumber - NumberToCreate
myRnd = Int(2 + Rnd * (MaxNumber - 2 + 1))
StartRow = myRnd
EndRow = myRnd + NumberToImport
wb.Sheets(2).Range("D" & StartRow & ":D" & EndRow).SpecialCells(xlCellTypeVisible).Copy
It works, sort of - it copies the correct amount of random cells but not from the visible range.
Could someone help me understand why, or indeed provide a far better solution?