Results 1 to 7 of 7

Using VBA to generate random numbers

Threaded View

  1. #1
    Registered User
    Join Date
    09-01-2008
    Location
    Halifax, UK
    Posts
    5

    Unhappy Using VBA to generate random numbers

    Dear Forum,

    I am using the VBA code below (bottom) to return random numbers for a selected area of cells where the range of random numbers is between 1 and the
    total number of cells. Unfortunately sometimes the random numbers appear more than once and I would like to amend this to ensure duplicates are not included, any help would be greatly appreciated, thanks, Matt

    Ps I have already tried substituting with VBUniqRandInt() but it returns #NAME? in every selected cell??, i.e;

    Sub RandomTable4()
    
    For Each r In Selection
        r.Formula = "=int(VBUniqRandInt() *" & Selection.Count & "+1)"
    Next
    End Sub
    
    Sub RandomTable4() ' but this returns duplicates
    
    For Each r In Selection
        r.Formula = "=int(Rand() *" & Selection.Count & "+1)"
    Next
    End Sub
    Last edited by shg; 09-01-2008 at 11:51 AM. Reason: add code tags

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 and matching all numbers
    By Zyphon in forum Excel General
    Replies: 2
    Last Post: 03-14-2008, 04:40 AM
  2. Random Numbers
    By zinzah in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-24-2008, 01:12 PM
  3. Generate Random Numbers
    By Rgaherty in forum Excel General
    Replies: 5
    Last Post: 10-30-2007, 04:08 PM
  4. generate random numbers from a frequency list
    By adeina in forum Excel General
    Replies: 11
    Last Post: 06-21-2007, 11:34 AM
  5. Generate random numbers with no repeats
    By Paul Sheppard in forum Excel General
    Replies: 4
    Last Post: 04-06-2007, 12:37 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