Results 1 to 19 of 19

Random numbers but 3 numbers in sequence not allowed.

Threaded View

  1. #1
    Registered User
    Join Date
    07-28-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    6

    Random numbers but 3 numbers in sequence not allowed.

    My worksheet has 20 columns and 500 rows. I wanted to populate my worksheet with random numbers: 6 numbers in every row. Problem is I do not want any row with 3 or more numbers in sequence eg 3-4-5 , 12-13-14, 15-16-17-18 etc. I try to modify some code I copy from somewhere to suit my need but the more I do, the more I get confused. Please help, somebody.

    For J = 1 To 500
     
          For I = 1 To 20
                my(I) = I
          Next I
     
         For K = 1 To 6 'pick 6 number per row
         Randomize
         NewNumber:
         Number = Int(20 * Rnd) + 1
         If my(Number) = "" Then
             GoTo NewNumber
         Else
            Cells(j + 1, Number + 1) = my(Number)
             my(Number) = ""
        End If
        Next K
    Next j
    Last edited by Cutter; 07-28-2012 at 03:18 PM. Reason: Added code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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