+ Reply to Thread
Results 1 to 13 of 13

Random numbers without a macro?

  1. #1
    Registered User
    Join Date
    08-23-2012
    Location
    89460
    MS-Off Ver
    Excel 2007
    Posts
    27

    Random numbers without a macro?

    I need to figure a way to make say cells A1 thru A10 produce random numbers from 0 to 9.

    I would like to do it without a macro if possible. I also need a button to generate those random numbers. I know this button may make it impossible to not use a macro, but let's see if someone can. If it has to be done with a macro then so be it. I would appreciate it if someone could help me out.

  2. #2
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Random numbers without a macro?

    hi cat3rn. you're right. it needs a macro if you want the button. Otherwise, you could give the user a simple instruction to generate them by pressing F9. F9 is to calculate. the numbers will change when done so. the formulas in A1 would be:
    =RANDBETWEEN(0,9)

    if you need the button,
    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  3. #3
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Random numbers without a macro?

    Hi cat3rn,

    You are correct - as soon as you ask for a button, you are involving macros.

    RANDBETWEEN(0,9) will give you random numbers, but it is volatile, and it won't only use each number once. In other words, it is likely that you will get the same number used more than once in A1:A10. (Volatile means that it recalculates every time the worksheet calculates - that is almost every time you enter something!)

    Is that what you want, or are you trying to get the digits 0 through 9 in a different order every time?

    Regards,

    David


    When you reply please make it clear WHO you are responding to by mentioning their name.

    If this has been of assistance, please advise. A little thanks goes a long way.
    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".

  4. #4
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,368

    Re: Random numbers without a macro?


  5. #5
    Registered User
    Join Date
    08-23-2012
    Location
    89460
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Random numbers without a macro?

    I am so sorry maybe I should have been more clear.

    I need to have cells A1 thru A 10 generate a random set of numbers each cell being a different number than any other in the range of cells.

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Random numbers without a macro?

    Hi cat3rn,

    Please see attached file. In column "B" are some numbers in the range of 0-9, Column "D" is a helper column and in "A" are numbers in the range of 0-9 that are not in column "B".
    Attached Files Attached Files
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  7. #7
    Forum Expert
    Join Date
    12-11-2011
    Location
    Netherlands
    MS-Off Ver
    office 365
    Posts
    3,293

    Re: Random numbers without a macro?

    Or use 2 functions in 2 different columns RAND() and RANK()
    Attached Files Attached Files
    Willem
    English is not my native language sorry for errors
    Please correct me if I'm completely wrong

  8. #8
    Registered User
    Join Date
    08-23-2012
    Location
    89460
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Random numbers without a macro?

    Quote Originally Posted by popipipo View Post
    Or use 2 functions in 2 different columns RAND() and RANK()
    I like this but need 0 thru 9 instead of 1 thru 10

  9. #9
    Forum Expert
    Join Date
    12-11-2011
    Location
    Netherlands
    MS-Off Ver
    office 365
    Posts
    3,293

    Re: Random numbers without a macro?

    Not so difficult I think
    =RANK(A1,$A$1:$A$10)-1

  10. #10
    Registered User
    Join Date
    08-23-2012
    Location
    89460
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Random numbers without a macro?

    Quote Originally Posted by popipipo View Post
    Not so difficult I think
    =RANK(A1,$A$1:$A$10)-1
    Great that works. Now I need to keep the values locked and not have them change anytime I input a value into another cell anywhere on the sheet.

  11. #11
    Registered User
    Join Date
    08-23-2012
    Location
    89460
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Random numbers without a macro?

    Quote Originally Posted by benishiryo View Post
    hi cat3rn. you're right. it needs a macro if you want the button. Otherwise, you could give the user a simple instruction to generate them by pressing F9. F9 is to calculate. the numbers will change when done so. the formulas in A1 would be:
    =RANDBETWEEN(0,9)

    if you need the button,
    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    I like this Macro. How would I make it randomize the numbers in certain cells like E4 to N4 and D5 to D14 only.

  12. #12
    Registered User
    Join Date
    08-23-2012
    Location
    89460
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Random numbers without a macro?

    I found out how to do something on my own. woo hoo I'm getting smarter by the year. lol On the Formulas tab > select Calculation > Select the Manual Radio Button. This makes all random numbers stay the same when inputting other data into the worksheet. I then recorded a Macro using just the F9 key. Assigned that macro to the button and WAH LAH the random numbers only change when I click the button.

  13. #13
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Random numbers without a macro?

    Try this...

    This will generate the numbers 0 to 9 in random order without repeats.

    Data Range
    A
    1
    Header
    2
    9
    3
    0
    4
    2
    5
    5
    6
    3
    7
    4
    8
    1
    9
    7
    10
    6
    11
    8
    12


    Create this named expression...

    Goto the Formulas tab>Define Name
    Name: Nums
    Refers to: ={0,1,2,3,4,5,6,7,8,9}
    OK out

    Enter this array formula** in A2 and copy down to A11:

    =SMALL(IF(ISNA(MATCH(Nums,A$1:A1,0)),Nums),INT(RAND()*(10-(ROWS(A$2:A2)-1)))+1)

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    There must be a cell above the first formula cell and this cell must not contain a number from 0 to 9.

    The order of the numbers will change every time a calculation is triggered.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

+ 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. [SOLVED] Macro to pick random unique numbers from lsit
    By dinesh_ltjd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-16-2012, 02:11 PM
  2. Unique random numbers daily calculation macro
    By pco101 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-14-2011, 04:43 AM
  3. Can I use a macro to enter Poisson random numbers?
    By raphile in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-19-2009, 12:08 PM
  4. Non-random numbers generated by excel's data analysis random gener
    By Allie in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-17-2005, 02:05 AM
  5. [SOLVED] Re: Non-random numbers generated by excel's data analysis random gener
    By Harlan Grove in forum Excel General
    Replies: 2
    Last Post: 09-13-2005, 12:05 PM

Tags for this Thread

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