+ Reply to Thread
Results 1 to 8 of 8

Unique, random selections from one sheet to another

  1. #1
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    65

    Unique, random selections from one sheet to another

    Good day all,

    I'm using Excel 2007 at work and am having issues with my current macro. The first one should be a simple fix, I hope. The macro creates two sheets in a workbook. The length of sheet1, 'checklog,' varies based on the total items imported. I need to have cell D2 be the total of blanks and dates over one year old based on Column E.

    Second, on sheet2: I need to either select a random sample, from sheet1, of IN USE items (column D) equaling 5% of the the total inventory. Or, 100% of the blanks and over one year old items, whichever will give the larger sampling. These need to populate sheet2 starting in cell A5

    Third, I'd like to have the items imported from above be numbered in column A

    With the attachments:
    Checklog.txt will import with 12 total items. One is over a year old and three have missing dates. The checklog tab cell D2 counts only 1, but I need it to have 4.

    Thank you so much for your help. I've been struggling with this for days.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: Unique, random selections from one sheet to another

    Okay, I realize no one wants to do someone's work for them. I've puzzled out my numbering issue and a way to include my blank spaces on the Checklog sheet. I've even adapted some code from this forum to make a random selection of my initial data (Thank you MarvinP). I'm still stuck on two things with this piece of my puzzle. Firstly, how do I code in the variable to select 100% of the items that are over one year old or missing an inventory date, or a unique selection equaling 5% of the total inventory? This could mean a combination of both items (i.e. there's one item over 365 days old, but I need to choose 5 items to validate). Secondly, how do I include the variable to randomly select only the items showing "IN USE" on Column D of the Checklog tab?

    Here's my code, as it is:
    Please Login or Register  to view this content.
    I've attached my updated Macro sheet as well.
    Thank you for looking at this.
    Attached Files Attached Files
    Last edited by Hoosaskin; 09-14-2011 at 03:51 PM.

  3. #3
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: Unique, random selections from one sheet to another

    Thanks to MarvinP, I've been able to select a random portion of my total to populate sheet 1 of my workbook. I'm still struggling with how to ensure they are unique samples, no duplicates, from my total inventory.

    I also need to be sure the sample includes all the items last accounted for over 1 year ago (checklog!d2).

    I was thinking of copying the lines after using the advance filter, but can't figure out how to get it working. I've commented out my feeble attempt in Sub Random().

    These latest attachments should generate an inventory list of 116 pieces, one over 1 year old. The total to validate is 6. Anyone have any suggestions?
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: Unique, random selections from one sheet to another

    Does anyone have any thoughts on how to prevent duplicate lines?

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Unique, random selections from one sheet to another

    You can have the duplicates deleted if there are some common fields to compare with.

  6. #6
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: Unique, random selections from one sheet to another

    The duplicates would show on the created sheet. The easiest piece to compare is the Entry Number (Column A or B, depending on when you look).

    While you're looking at this, what's the best way to ensure anything over 1 year old is always a part of the created, random list?

    Thank you.

  7. #7
    Registered User
    Join Date
    08-18-2011
    Location
    Denver Colorado
    MS-Off Ver
    Excel 2007
    Posts
    65

    Re: Unique, random selections from one sheet to another

    Anyone have any thoughts? The duplicates only show on the new sheet because of the sub Random().
    Last edited by Hoosaskin; 10-28-2011 at 12:06 PM.

  8. #8
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Unique, random selections from one sheet to another

    Linked to here.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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