+ Reply to Thread
Results 1 to 13 of 13

Random Selection

  1. #1
    Registered User
    Join Date
    01-01-2012
    Location
    Richmond
    MS-Off Ver
    Excel 2003
    Posts
    42

    Random Selection

    Happy New Year to you all.

    I am pretty much useless at Excel and have MS Excel 2003 hence I am posting here. I have a golf game with loads of different courses to play with varying tournament conditions.

    a) I have created a file of golf courses, and on sheet 8 is the full list of the courses in column B totaling 1956 names currently (this list will grow over a period of time). I am trying to make a random selection from these names to appear on sheet 1 every time I click a button. (I do know how to create a button and assign a macro to it lol)

    b) I would also like on sheet 1 to show different random conditions so just by the click of one or two buttons I can see what course I am to play and with what conditions. The conditions are as follows :-

    Conditions) No Wind : Breezy : Gusty : Windy
    Greens) Soft : Moderate : Firm
    Green Speed) Slow : Medium : Fast
    Tees) Back : Middle : Forward : Juniors : Ladies

    All help is greatly appreciated

    Thanks In Advance

    Steve

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Help With A Random Selection

    You could do this in a formula, then all you'd have to do is press F9 to recalculate to get a new result.

    Assuming your list of courses starts at row 1 and that sheet 8 is called Sheet8 then on sheet 1 try:

    =INDEX(Sheet8!B:B,RANDBETWEEN(1,COUNTA(Sheet8!B:B))) & ", conditions " & CHOOSE(RANDBETWEEN(1,4),"no wind","breezy","gusty","windy") & ", greens - " & CHOOSE(RANDBETWEEN(1,3),"soft","moderate","firm") & " and " & CHOOSE(RANDBETWEEN(1,3),"slow","medium","fast") & ", tees - " & CHOOSE(RANDBETWEEN(1,5),"back","middle","forward","ladies","juniors")

  3. #3
    Registered User
    Join Date
    01-01-2012
    Location
    Richmond
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Help With A Random Selection

    Thanks Andrew I will have a go right now
    Last edited by StephenSmith; 01-01-2012 at 12:33 PM.

  4. #4
    Registered User
    Join Date
    01-01-2012
    Location
    Richmond
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Help With A Random Selection

    Andrew that formula is returning :- #NAME?

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Help With A Random Selection

    Sorry, I don't think Excel 2003 supports the RANDBETWEEN function. My mistake.

    We could do it just using the RAND function, but it would make a long formula even longer. I'll knock up some macro code for you...

  6. #6
    Registered User
    Join Date
    01-01-2012
    Location
    Richmond
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Help With A Random Selection

    thanks so much......and all macro code help on what to do with it would be greatly appreciated

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Help With A Random Selection

    OK, here's some code - I've tried to make it well structured and readable, rather than short and snappy, but it should do everything you need.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-01-2012
    Location
    Richmond
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Help With A Random Selection

    thanks andrew...sounds like a dumb question what do I do with this

  9. #9
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Help With A Random Selection

    Quote Originally Posted by StephenSmith View Post
    I do know how to create a button and assign a macro to it lol
    Ah, I take it there's a "not" missing from that sentence then

    I honestly can't remember how to insert buttons in Excel 2003, perhaps somebody else can help you with that, but what you could do is:

    Press Alt-F11 to open the VB editor
    From the "Insert" menu select "Module" (NOT class module)
    Paste my code in, but change the first line to read something like "Sub GolfPick()"
    Close the VB editor

    In, I think, the tools menu there's an option to view macros. Click that and you'll get a list with one macro in, click on the options button and it will let you assign a shortcut key to run the macro. That should be it.

    At the moment it is set to output to cell A1 on sheet 1, if you want the result in a different cell then change the line:

    Please Login or Register  to view this content.
    To the cell reference where you want it to output, e.g.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-01-2012
    Location
    Richmond
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Help With A Random Selection

    Andrew thanks so much that is very kind of you

  11. #11
    Registered User
    Join Date
    01-01-2012
    Location
    Richmond
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Random Selection

    Andrew that is absolutely brilliant many thanks works a treat...could I ask one more thing please

    If I want the the course name to be displayed in cell D7 without the name course beforehand, the conditions displayed in cell E7, Greens in cell F7, Green Speed in G7 and the tees in H7

    would you be so kind to change the code for me please

    thank you

  12. #12
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Random Selection

    Of course, not a problem - glad it worked for you.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    01-01-2012
    Location
    Richmond
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Random Selection

    Brilliant Andrew thanks so much

+ 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