View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Saarang84[_2_] Saarang84[_2_] is offline
external usenet poster
 
Posts: 1
Default How to choose Random rows??


broro183;740587 Wrote:

hi Sarang,


Please keep the responses in the thread so that any other helpers or
people looking for answers can also see the same information.


Do you want x rows marked from each time the filter changes on the
below lines of code?
Or do you want a total of x rows (after all the looping is done)?



VBA Code:
--------------------


For i = 1 To 10
Columns("A:J" & Cells(Rows.Count, 1)).AutoFilter field:=1, Criteria1:="=" & i
--------------------




Rob



Hi Rob,

Based on the number of rows filtered (by the below line) the value of x
is calculated. Out of the total no. of rows filtered by this line, these
x rows are to be marked as samples *randomly*.



VBA Code:
--------------------


For i = 1 To 10
Columns("A:J" & Cells(Rows.Count, 1)).AutoFilter field:=1, Criteria1:="=" & i
--------------------




For example, when i=1, say the number of rows filtered may be 200, then
x=10 rows (5% of 200), need to be marked as samples. When i=2, say the
number of rows filtered is 150, then If x=7.5 rows (5% of 150) or 8 rows
(ceiling value) need to be marked as samples randomly. This 5% of total
visible rows is just an example, actually its z% of total visible rows
in the filter from which x rows are calculated and to be chosen
randomly.

Hope this clarifies better.

Since this is a test data, 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)


Sarang


--
Saarang84
------------------------------------------------------------------------
Saarang84's Profile: http://www.thecodecage.com/forumz/member.php?u=2386
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=207872

http://www.thecodecage.com/forumz


--- news://freenews.netfront.net/ - complaints: ---