+ Reply to Thread
Results 1 to 3 of 3

No repeat of last ten numbers (Randbetween())

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2013
    Location
    los angeles
    MS-Off Ver
    Excel 2010
    Posts
    4

    No repeat of last ten numbers (Randbetween())

    I am looking to build a workbook that uses the randbetween function to randomly choose numbers but does not select numbers that were selected in the previous 15 randbetween cells. How would I do this? I have come down to the conclusion that this can only be solved with VBA, which I am still a noobie in.

    This is the structure of the workbook.

    Column A (1000 rows): Randbetween(1,100)
    Column B (985 rows, starts 15 rows down): Randbetween(1,100) but rerun the randbetween(1,100) if initial number provided was selected in previous 15 rows. I want to have 15 columns of this in which now it accounts for the previous 15 rows and each prior column.

  2. #2
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: No repeat of last ten numbers (Randbetween())

    responding to the title of your thread, here's a code for producing non-repeating random groups of 10

    put it in a code module and run it on a blank worksheet to see what it does

    perhaps you can adapt it to the desired structure of your workbook
    Sub maslik()
    
    Const n As Long = 10
    Const q As Long = 15 'for randbetween 1 and q
    Const c = 8 'desired number of columns
    
    Dim b() As Boolean
    Dim j As Long, s As Long, x As Long
    
    For j = 1 To c
    ReDim b(q)
    s = 0
        Do
            x = Application.RandBetween(1, q)
            If Not b(x) Then
                s = s + 1
                Cells(s, j) = x
                b(x) = True
            End If
        Loop Until s = n
    Next j
    
    End Sub

  3. #3
    Registered User
    Join Date
    01-02-2013
    Location
    los angeles
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: No repeat of last ten numbers (Randbetween())

    Quote Originally Posted by kalak View Post
    responding to the title of your thread, here's a code for producing non-repeating random groups of 10

    put it in a code module and run it on a blank worksheet to see what it does

    perhaps you can adapt it to the desired structure of your workbook
    Sub maslik()
    
    
    
    Const n As Long = 10
    Const q As Long = 15 'for randbetween 1 and q
    Const c = 8 'desired number of columns
    
    Dim b() As Boolean
    Dim j As Long, s As Long, x As Long
    
    For j = 1 To c
    ReDim b(q)
    s = 0
        Do
            x = Application.RandBetween(1, q)
            If Not b(x) Then
                s = s + 1
                Cells(s, j) = x
                b(x) = True
            End If
        Loop Until s = n
    Next j
    
    End Sub
    Kalak, thanks for the reply. I actually figured out a way to make it work without VBA although it was very tedious (6 tabs and match functions). I will give this code a shot sometime when my coding knowledge is up to par.

+ 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] Randbetween excluding certain letters/numbers
    By Wheelie686 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-13-2018, 03:58 PM
  2. [SOLVED] Randbetween - not to repeat or duplicate
    By itselflearn in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 05-01-2017, 03:18 PM
  3. How to exclude numbers from RANDBETWEEN function?
    By mathteacher in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-01-2013, 04:50 PM
  4. Replies: 8
    Last Post: 09-21-2011, 06:50 PM
  5. Random numbers not using randbetween()
    By davehill1974 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-07-2005, 12:05 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