LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Richard Buttrey
 
Posts: n/a
Default Randomly Generated List / Macro

On Sat, 8 Apr 2006 05:08:02 -0700, carl
wrote:

I have a list of 60000 products. These products are grouped into 500
categories (for example ABC, EFG ,HIJ).

I would like to randomly generate a list of 100 products given a category.
For example, for category ABC, I would like the macro to generate a list of
100 products.

Is this possible ?

Thank you in advance.



One way

With the name "Products" in A1, "Cat" in B1, Product numbers in
A2:A60001, and categories in B2:B60001

Put your chosen category in C2 and run the folloiwng macro.

This will first extract all the products for your chosen category in
columns E & F, then enter a random number in column G2:Gxx, then sort
columns E:G, and finally number column G starting at 1 and
incrementing by 1

You will then have all your products for the chosen category listed in
random order. If you want 100, just pick off numbers 1-100 in column G


Sub RandProducts()
Range("a1:B60001").AdvancedFilter Action:=xlFilterCopy,
Criteriarange:=Range("C1:c2"), copyToRange:=Range( _
"E1:F1"), Unique:=False

Range(Range("F2"), Range("F2").End(xlDown)).Offset(0, 1) =
"=Rand()"
Range(Range("G2"), Range("G2").End(xlDown)).Copy
Range("G2").PasteSpecial (xlPasteValues)
Range(Range("E2"), Range("G2").End(xlDown)).Sort key1:=Range("G2")

Range("G2") = 1: Range(Range("G2"),
Range("G2").End(xlDown)).DataSeries step:=1

End Sub

Watch any word wrap above. Adjust for your data range

HTH
__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I randomly shuffle a word list in Excel? Arun Agarwala Excel Discussion (Misc queries) 1 March 30th 06 06:11 PM
Finding and compiling list of cells containing data... Richard Walker Excel Worksheet Functions 6 March 18th 06 02:17 PM
List Box with macro VETcalc Excel Worksheet Functions 2 February 28th 06 04:05 PM
running a macro from a list rufusf Excel Worksheet Functions 0 February 22nd 06 04:38 PM
How to randomly select from a list with condition kathyxyz Excel Worksheet Functions 5 July 27th 05 04:19 PM


All times are GMT +1. The time now is 05:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"