Hi Wizards,
This is a cross post from the MrExcel Message Board.
Thread Link: How to choose Random rows??
Its working as i intend it to, but i need to fix it a little bit. Refer the code in attached workbook.
The below line of code needs to be tweaked:
[vba]
.Resize(.Rows.Count - 1, 1).Offset(i, fCol).SpecialCells(xlCellTypeVisible) = "Sample_" & i
[/vba] I want to mark only certain number of rows (stored in the variable randRow) as samples out of the total number of visible rows. But the above line of code marks all the rows filtered. How can this be fixed to randomly mark only the number of rows stored in randRow??
The x number rows which have to be marked is calculated each time the filter changes on the below lines of code:
[vba]
For i = 1 To 10
.Columns("A:J" & Cells(Rows.Count, 1)).AutoFilter field:=1, Criteria1:="=" & i
[/vba]
In general, out of the total number of rows filtered, say y, i need to choose x rows randomly (where x<y).
This is a test data in which i use a for loop (from 1 to 10) and filter each time for 1,2 ...10. Actually, my original data contains a list of names in an array (called names(i), and i=1 to n, for n names in general) and i need to loop for all the n names.
Sarang