+ Reply to Thread
Results 1 to 11 of 11

Code to randomize within a filter

  1. #1
    Forum Contributor
    Join Date
    06-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    104

    Code to randomize within a filter

    I was presented a scenario from my boss and was wondering if somebody could help me out. My sample spreadsheet attached has only 1,500 records but the actual one has about 10,000 records and was wondering if there was a code to help me reduce my sample.

    I was asked to find a way to find a way where I could randomly select 2 records for each client. The catch is that the 2 records have to be different states.

    To further complicate things, I have to do this once a month and for each month, I need records on states that have yet to be selected until all 50 states are selected, and then the process starts over again.

    I was wondering if there was a code that could me with at least some of this process but any ideas, suggestions, comments, anything would be greatly appreciated. I don't know where to start.

    Thanks!
    Scott
    Attached Files Attached Files

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Code to randomize within a filter

    Hi Scott,
    maybe something like this
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    06-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    104

    Re: Code to randomize within a filter

    Now does that run automatically or would I have to run a macro/create a button?

    Also the spreadsheet I'm working with has the same objective, but column A in my sample spreadsheet is column J and my column B in the sample is column F in my company spreadsheet. How much does that change the code?

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Code to randomize within a filter

    here is your file with a button
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    06-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    104

    Re: Code to randomize within a filter

    Oh awesome! Thank you. I have another question for you. Is there a way to clear the contents and then click the same button to yield more results. So after the first month I would could repeat the process.

    Also, is that randomized because after I clicked the button almost every 2 records for each client was AK and CA. Either that's a crazy coincidence but it seems almost alphabetical.

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Code to randomize within a filter

    then let's try this
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    06-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    104

    Re: Code to randomize within a filter

    Oh awesome!! I just have a few more question about making some modifications. If I were to put the data onto another sheet? Would that change the code at all? Also, although I'm only using columns F and J, is it possible to transfer the entire row over to the new sheet?

    Thank you!!

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Code to randomize within a filter

    Scott,
    without your example, I can only say that this is possible

  9. #9
    Forum Contributor
    Join Date
    06-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    104

    Re: Code to randomize within a filter

    Okay I'll make a sample spreadsheet for you and post it when I get back into work tomorrow. Thanks for all of your help today!

  10. #10
    Forum Contributor
    Join Date
    06-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    104

    Re: Code to randomize within a filter

    Hello,

    so I attached a spreadsheet that isn't exactly the same as my actual one, but it's the same design. I was wondering if there was a way to put the data selected onto a new sheet, or at the very least have the data selected with the code already used, but move the entire row over to the gray box. I was really hoping to do this without using an Index/Match equation.

    Thanks.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    06-18-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    104

    Re: Code to randomize within a filter

    Actually, it would be better if I could just duplicate the record in a different area after pressing the button

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Code the saves filter info to reapply after running other code
    By Wedge120 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-25-2011, 05:49 PM
  2. Randomize
    By Valkyrie1981 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2010, 11:27 AM
  3. Randomize
    By shaun0_0 in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 09-12-2008, 02:24 PM
  4. Randomize
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-19-2008, 06:46 AM
  5. [SOLVED] Randomize
    By Davor ®upaniæ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2005, 02:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1