+ Reply to Thread
Results 1 to 11 of 11

Static random non-repeating number generator

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

    Static random non-repeating number generator

    I can use a formula to generate random non-repeating numbers but the formula uses volatile functions which means the numbers change at each calculation.

    Does anyone have a UDF that will do this that is not volatile?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Static random non-repeating number generator

    Why a UDF and not just a macro?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

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

    Re: Static random non-repeating number generator

    With a UDF you would have the versatility of defining the number range.

    =RANDNUMS(start_num,end_num)

    =RANDNUMS(100,150)

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Static random non-repeating number generator

    Yeah, but a function can only write a value to the cell in which it sits.

    Pete

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Static random non-repeating number generator

    Quote Originally Posted by Tony Valko View Post
    With a UDF you would have the versatility of defining the number range.

    =RANDNUMS(start_num,end_num)

    =RANDNUMS(100,150)
    So you want it to be Volitile with just the input numbers assuming they reference two cells? If yes, you could use the Worksheet_Change event procedure. If No, a macro could prompt for start_num,end_num. Not to beat a dead horse here, but I still don't see the need for a UDF.

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Static random non-repeating number generator

    Try my luck :

    Please Login or Register  to view this content.
    Usage :
    This UDF is to be used as array formula.
    For example,
    select A1:A10, press F2, and type =RANDNUMS(1,20) , confirmed with "Ctrl Shift Enter" keys
    select C1:G1, press F2, and type =RANDNUMS(1,20) , confirmed with "Ctrl Shift Enter" keys
    select C4:D7, press F2, and type =RANDNUMS(1,20) , confirmed with "Ctrl Shift Enter" keys

    If number of cells selected is more than available unique numbers, the UDF will return a message.
    Last edited by karedog; 08-11-2016 at 12:51 PM. Reason: Fix nStart
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

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

    Re: Static random non-repeating number generator

    Tried it in Excel 2010 and it just hangs.

    Selected A1:A5 and array entered:

    =RANDNUMS(1,5)

    Have to kill it using Task Manager!

  8. #8
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Static random non-repeating number generator

    Sorry, I already fix the code before you posting. Please check the fixed code.

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

    Re: Static random non-repeating number generator

    Quote Originally Posted by karedog View Post
    Sorry, I already fix the code before you posting. Please check the fixed code.
    Excellent!

  10. #10
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Static random non-repeating number generator

    Thanks

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

    Re: Static random non-repeating number generator

    This is what led me to post this question:

    https://www.excelforum.com/showthread.php?t=1151246

+ 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. Random Number Generator
    By Chetan_raghu in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2016, 08:56 AM
  2. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  3. [SOLVED] Non Repeating Random Number Generator
    By Bob1980 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-28-2012, 10:12 AM
  4. Random Number Generator
    By phattony72 in forum Excel General
    Replies: 2
    Last Post: 02-19-2008, 12:56 PM
  5. Random number generator
    By uncee in forum Excel General
    Replies: 6
    Last Post: 08-14-2007, 03:05 PM
  6. [SOLVED] Random Number Generator help
    By Shani in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2006, 11:35 AM

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