+ Reply to Thread
Results 1 to 11 of 11

Auto select in a drop down box

  1. #1
    Registered User
    Join Date
    02-23-2007
    Posts
    4

    Auto select in a drop down box

    Hi.

    I have a drop down box using data validation, and I'm currently designing staff rosters. I want to be able to let Excel randomly select a value in the drop down box.

    Eg.
    If i have
    FRANK SMITH
    FRED LONG
    KATIE KIT
    in a drop down box, can i let excel automatically select one of those names?

    thanks for your help in advance!
    aidan g

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    Try this...

    Sub Demo()
    MyList = Range("A1").Validation.Formula1
    MyArray = Split(MyList, ",")
    MyChoice = Int((UBound(MyArray) + 1) * Rnd())
    Range("A1") = MyArray(MyChoice)
    End Sub

    assuming validated cell is A1 and you have no commas in your possible validated values.
    Martin

  3. #3
    Registered User
    Join Date
    02-23-2007
    Posts
    4
    Hey,

    Sorry to be a bit of a nuisance, but could you possibly apply the formula in a sheet and show me how t works... I'm a little confused.

    Thanks for this! your a life saver!

    aidan g.

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Its a macro, not a formula.

    Hit alt F11, right click on the explorer tree to add a module and paste the code in there.

    Then back on the worksheet, hit tools-macros-run to run the macro.

  5. #5
    Banned User!
    Join Date
    10-14-2006
    Posts
    1,211
    Quote Originally Posted by aidang
    Hi.

    I have a drop down box using data validation, and I'm currently designing staff rosters. I want to be able to let Excel randomly select a value in the drop down box.

    Eg.
    If i have
    FRANK SMITH
    FRED LONG
    KATIE KIT
    in a drop down box, can i let excel automatically select one of those names?

    thanks for your help in advance!
    aidan g
    Assuming name list in A2:A10
    B1: holds data validation list

    Data Validation
    Allow:List
    Source:=INDEX($A$2:$A$10,RANDBETWEEN(1,10))
    to random select name by select the drop down of validation list

  6. #6
    Registered User
    Join Date
    02-23-2007
    Posts
    4
    thanks for all your suggestions...

    with the macro, if i had commas, what would it do?

    thnx... (sorry for being a pain! )

  7. #7
    Registered User
    Join Date
    02-23-2007
    Posts
    4
    hey.

    im sorry mrrice, but im completely lost. i dont get it... could you break it down for dumb people like me plz?

    thnx for all ur help...
    aidan.

  8. #8
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Here's the macro inserted - hit Alt F11 to see it in module1
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-18-2013
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Auto select in a drop down box

    Mrice. I stumbled upon this thread. I'm trying to do a similar thing. Can you help me?

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

    Re: Auto select in a drop down box

    textexpress,

    Welcome to the forum.

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  11. #11
    Registered User
    Join Date
    12-18-2013
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Auto select in a drop down box

    Thanks for the feedback. I will repost. Thanks again.

+ 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