+ Reply to Thread
Results 1 to 6 of 6

Command Button to Choose Random Number from LIST NOT RANGE

  1. #1
    Registered User
    Join Date
    10-14-2014
    Location
    Staunton, VA
    MS-Off Ver
    Excel 2010 Professional
    Posts
    9

    Command Button to Choose Random Number from LIST NOT RANGE

    I would like to create a command button that each time it's clicked will populate a cell with one number from the following list: (1,3,5,7,9). I'd also like to create a separate command button that will populate a different cell with one number from this list: (2,4,6,8) It's ok for the same numbers to appear again on subsequent clicks of their respective buttons.

    Private Sub CommandButton1_Click()
    Range("BH3") = WorksheetFunction.RandBetween(1, 9)
    End Sub

    works fine for selecting from the entire range of numbers between 1 & 9 but can't figure out how to select from just the odd and even numbers between 1 & 9.

    If someone could provide some sample code to accomplish this it would be greatly appreciated.

  2. #2
    Forum Contributor
    Join Date
    07-19-2012
    Location
    Redmond, WA
    MS-Off Ver
    O365
    Posts
    133

    Re: Command Button to Choose Random Number from LIST NOT RANGE

    It doesn't look like it will do odd or even, but:
    https://www.techonthenet.com/excel/formulas/rnd.php

    Please Login or Register  to view this content.
    Result: random number between 1 and 9
    Rep is appreciated. Click my * if I helped.

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Command Button to Choose Random Number from LIST NOT RANGE

    Hi Ghostrider55,

    Try these macros:

    Please Login or Register  to view this content.
    Please wrap any code you post in the applicable tags i.e. [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] as I have done. Thanks.

    Regards,

    Robert
    Last edited by Trebor76; 11-04-2019 at 06:45 PM.
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Command Button to Choose Random Number from LIST NOT RANGE

    Hey GR55,

    How about using an IsOdd or IsEven function in your quest. Something like:

    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Registered User
    Join Date
    10-14-2014
    Location
    Staunton, VA
    MS-Off Ver
    Excel 2010 Professional
    Posts
    9

    Re: Command Button to Choose Random Number from LIST NOT RANGE

    Robert - apologize for not tagging the code in my post and thanks for the reminder. Your macros work great so thanks for the response. The other one suggested below using IsOdd and IsEven works as well so I now have 2 options to choose from whereas before I had none. Thanks Again!

  6. #6
    Registered User
    Join Date
    10-14-2014
    Location
    Staunton, VA
    MS-Off Ver
    Excel 2010 Professional
    Posts
    9

    Re: Command Button to Choose Random Number from LIST NOT RANGE

    MarvinP - Works like a charm, Thank You!

+ 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. Replies: 1
    Last Post: 10-31-2019, 06:49 PM
  2. Create unique random number after hitting command button
    By vbogaert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2018, 10:17 AM
  3. Choose random number from list
    By ricklou in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 12-05-2016, 06:52 AM
  4. [SOLVED] Choose Random Number within range
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-12-2016, 11:49 AM
  5. [SOLVED] Choose random number between given values
    By Hitch75 in forum Excel General
    Replies: 3
    Last Post: 07-02-2015, 06:27 AM
  6. Command button linked to docket number range.
    By bumble1290 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2013, 02:24 AM
  7. Choose Random Value Based On List
    By kblaine in forum Excel General
    Replies: 5
    Last Post: 04-20-2011, 02:41 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