+ Reply to Thread
Results 1 to 13 of 13

generate random results, removing only SOME duplicates

  1. #1
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    generate random results, removing only SOME duplicates

    I've attached an example workbook.

    Right now, I have it functioning where the report tab will read the data from the DATA tab, then remove duplicates of that data when the "Generate Report" commandbutton is pressed, leaving only one person with the same name listed. I would like to add the option of choosing how many duplicates to remove, leaving a desired amount of persons with the same name listed, if there are that many. For instance, my example includes 4 "joe smith"s, 1 "tracy johnson", and 2 "steve wright"s. I want to be able to choose to leave 2 of each. So that would leave 2 of the "joe smith"s, and the still populate the 1 "tracy johnson" and the 2 "steve wright"s. And/or I want to be able to choose to leave 3 of each, which would then leave 3 of the "joe smith"s and still populate the 1 "tracy johnson" and the 2 "steve wright"s, etc, etc.
    I've been told it's a VBA issue....
    Is this possible? if so, how? Thanks!

    example.xlsm

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: generate random results, removing only SOME duplicates

    you have a bit of code that looks like this:
    Please Login or Register  to view this content.
    (to view this press alt+F11 to open the vba developed and look in module1 or module2).

    I'm not overly familiar with the .removeduplicates method but I would assume you can't choose how many to leave, therefore you probably need to write your own "code" to remove a certain number of duplicates. If you replace the code above with the code below and change the number of "number_of_duplicates_left" as neccessary, that should work.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: generate random results, removing only SOME duplicates

    I get "Sub or Function not defined" pop-up and the second "Range" is highlighted in the fifth line... I'm not sure how to fix, please help

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: generate random results, removing only SOME duplicates

    sorry, try replacing countif with worksheetfunction.countif

  5. #5
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: generate random results, removing only SOME duplicates

    now i get "Method 'Range' of object '_Global' failed" error, now I'm really lost! help!! Thank you!

  6. #6
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: generate random results, removing only SOME duplicates

    its just missing b
    Please Login or Register  to view this content.
    Give Feedback and Click(*)

  7. #7
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: generate random results, removing only SOME duplicates

    I made the modifcation, but when i run the code, it keeps going and going. Ultimately I have to force quit Excel to stop it and unfreeze other open documents. I tried modifying the range (B1:B500) to no avail . Any suggestions?

  8. #8
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: generate random results, removing only SOME duplicates

    try this

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: generate random results, removing only SOME duplicates

    same result... continuous execution, have to force quit. Please advise Thanks again for all your help!

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: generate random results, removing only SOME duplicates

    I don't believe it is continuous execution, I think it is just taking a long time. It might help speed things up if you turn calculation and screenupdating off.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: generate random results, removing only SOME duplicates

    awesome, this does execute, although it takes a couple minutes. How do I get the commandbuttons to stop moving around after this code is run?

  12. #12
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: generate random results, removing only SOME duplicates

    Change the property of the command button to "don't move or size with cells"

  13. #13
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: generate random results, removing only SOME duplicates

    perfect, just did that, trying it now you guys are awesome, thanks so much for the help

+ 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. generate random results, removing only SOME duplicates
    By jrosko1 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-02-2013, 04:54 PM
  2. Auto-Generate random set of four numbers without duplicates?
    By adrien23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2011, 06:03 PM
  3. Removing Duplicates based on two Columns, Output results to new Spreadsheet
    By crush in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2009, 02:26 PM
  4. How to generate sets of random numbers without having duplicates
    By William in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-06-2006, 12:35 AM
  5. generate a random number and use if function to generate new data
    By Dogdoc1142 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-25-2006, 10:50 PM

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