PDA

View Full Version : How to pick the random numbers from a set of numbers



ganesh3084
07-27-2011, 02:48 AM
Hi all


Im creating a macro which consists of two excel files.
in one excel file, there are four fields named Sno,Name ,Ps ID and Case ID. The user will provide Sno,name and PS ID.
I need to run a macro of which for Each Name, i need to pick 5 CaseIDs Randomly which is presented in a another excel file which has list of CaseIDs .
I need to check the count of CaseIDs presented in the Second Excel As Well.
I knew that i need to use Rnd() function. But i dont know how to code it since im very new to excel vba.

Plz suggest me

i have posted the original thread in the following forum link
http://www.ozgrid.com/forum/showthread.php?t=156529

Ganesh. V

p45cal
07-27-2011, 04:00 AM
Principle:
In the sheet/workbook with the list of CaseIDs (I guess the IDs are in a single column), add a new column to the table with =RND() in all the cells, sort the table ONCE on that new column, now you can pick off cases in chunks of 5 rows at a time, starting at the top and working your way down the table.

ganesh3084
07-27-2011, 05:23 AM
Principle:
In the sheet/workbook with the list of CaseIDs (I guess the IDs are in a single column), add a new column to the table with =RND() in all the cells, sort the table ONCE on that new column, now you can pick off cases in chunks of 5 rows at a time, starting at the top and working your way down the table.

Hi Thanks for ur timely response. Ya ID are in a single column

Well actually i need to do these through writting VBA Code. Can u please furnish some sample code regarding..

p45cal
07-27-2011, 05:24 AM
Record a macro of you doing it and copy the code here, then we'll tidy it up.

ganesh3084
07-27-2011, 05:27 AM
Record a macro of you doing it and copy the code here, then we'll tidy it up.

thanks
i will check it and revert