Results 1 to 6 of 6

Thread: Random Unique Number Generator Excel VBA

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by Excel Fox View Post
    Here's a way to generate unique random numbers from a minimum value to a maximum value
    Assuming you meant the "from a minimum to a maximum value" to mean the user can set those values to their own values, I think your code is not correct. I believe this modification to it will perform correctly...
    Code:
    Sub GenerateRandomUnique()    Dim lng As Long
        Const lngMax As Long = 100
        Const lngMin As Long = 1
        With CreateObject("Scripting.Dictionary")
            Do While .Count <= lngMax - lngMin          'removed the greater than symbol
                lng = Rnd * (lngMax - lngMin) + lngMin  'removed the +1
                .Item(lng) = Empty
            Loop
            MsgBox Join(.Keys, " ")
        End With
    End Sub
    Last edited by Rick Rothstein; 10-17-2012 at 09:17 PM.

Similar Threads

  1. Dynamic Worksheet Generator Sheet Copy
    By mfaisalrazzak in forum Excel Help
    Replies: 2
    Last Post: 03-01-2013, 05:38 PM
  2. Unique Random Number In Ascending Order
    By marreco in forum Excel Help
    Replies: 8
    Last Post: 11-04-2012, 04:15 PM
  3. Replies: 2
    Last Post: 01-07-2012, 12:11 AM
  4. Create Random Number Generator VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 1
    Last Post: 12-01-2011, 10:51 AM
  5. Generate random numbers in Excel
    By Mahesh in forum Excel Help
    Replies: 3
    Last Post: 10-06-2011, 11:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •