+ Reply to Thread
Results 1 to 9 of 9

random numbers to equal a total

  1. #1
    Registered User
    Join Date
    06-02-2010
    Location
    n.ireland
    MS-Off Ver
    Excel 2007
    Posts
    91

    random numbers to equal a total

    Hello all,

    I am trying to put together teams for a golfing outing and i would appreciate your help.
    In attached i have players in colA and there rating in colB.
    What i was hoping to do in G17 if i write in a total,i would like col G to pull 10 random numbers from colB that equall that total in G17 and col F will show there matching players.
    If you can help,thank you.
    Attached Files Attached Files
    Last edited by dealer; 10-09-2010 at 03:19 AM.

  2. #2
    Registered User
    Join Date
    04-29-2010
    Location
    McLean, VA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    87

    Re: random numbers to equal a total

    See the Attached.

    It does not work exactly as you need it so hopefully someone else can help improve what I have done. Anyhow, this works to the extent that in cell F32 you can type in the # of golfers you want on a team. Once you type that in, just keep hitting the refresh button that I've embeded until you get to the total Start rating for the team that you want. When you open the sheet, you will have to enable macros for this to work.

    For example, if you enter 10 team members in cell F32 and want a total star rating of 38, then just keep hitting the refresh button until you get to the number 38 in cell G32. Once you have that, you should double check to make sure none of the players are duplicates. If they are, then just keep hitting the refresh button again until you get to 38 once more and hopefully that time around you won't have duplicates.

    That's what I've got for now. I'll be interested to see what other might be able to add to this, but at least it accomplishes what you need for the time being.
    Attached Files Attached Files
    The Exceller
    If I helped you, please add to my reputation by clicking on the scale by my name in this post.

  3. #3
    Registered User
    Join Date
    06-02-2010
    Location
    n.ireland
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: random numbers to equal a total

    Thank you kindly for you spreadsheet.
    I can work no problem with your spreadsheet,but i still would like to see if it can be done the way i described.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: random numbers to equal a total

    Can't help thinking you might have to press the refresh button a lot of times ...

    This modification loops around until the sum in G32 matches a target in H32 ... obviously the cells can be switched around.

    Please Login or Register  to view this content.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: random numbers to equal a total

    A combined effort ... your workbook, The Exceller's idea and formulae (slightly modified) and my code (again, based on The Exceller's suggestion)

    See the attached workbook.

    Still the caveat that you might get duplicates ...

    Regards
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-02-2010
    Location
    n.ireland
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: random numbers to equal a total

    Thank you TMShucks,i really appreciate your code it works a treat.
    and again to The exceller,thank you.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: random numbers to equal a total

    @dealer: just beware, because of the nature of this solution, the player list will regenerate if you do *anything* on the spreadsheet, for example, enter a character in a cell and press enter. The new list may well not meet the criteria. You can press the Refresh button but then whatever you keyed in may not be relevant.

    There's no way to suppress this, AFAIK. I would recommend that, once you have a list of players that matches your star ratings, you copy the data and Paste Special | Values to another location to fix (?) the results.

    Regards

  8. #8
    Registered User
    Join Date
    04-29-2010
    Location
    McLean, VA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    87

    Re: random numbers to equal a total

    Good Call TMShucks. That is definitely something to be aware of. Also, great work on the code you suggested. I'm impressed and learned something from it as well. I hope it's working for you Dealer.

  9. #9
    Registered User
    Join Date
    06-02-2010
    Location
    n.ireland
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: random numbers to equal a total

    yes it's working well for me,and i also learned something new from you both.

+ 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