Consulting

Results 1 to 5 of 5

Thread: Random

  1. #1

    Random

    Annex file is an example...

    Each participant have a unique number (1000 => 1060).
    The participant receive for each serie a number of a ticket.

    BUT.
    The participant may never get the same batch number assigned.

    I search a macro that give the participants a ticket for the serie (random assigned).


    Thanks
    Random.xls

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    [vba]Sub snb()
    Randomize
    ReDim sn(59, 1)

    For j = 0 To UBound(sn)
    sn(j, 0) = Rnd
    Next

    Range("A1:A60") = sn
    Range("A1:A60") = [index(1000+rank(A1:A60,A1:A60),)]
    End Sub[/vba]

  3. #3
    Quote Originally Posted by snb
    [vba]Sub snb()
    Randomize
    ReDim sn(59, 1)

    For j = 0 To UBound(sn)
    sn(j, 0) = Rnd
    Next

    Range("A1:A60") = sn
    Range("A1:A60") = [index(1000+rank(A1:A60,A1:A60),)]
    End Sub[/vba]
    Maybe misinterpreted...

    What I asked was a new assigned ticket in sheet 3 (col D, Q, AD, Q)
    Available tickets in column A (sheet 3)
    The tickets (col A) can be different in each sheet

  4. #4
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    Not quite sure if this is what you are looking for, but hopefully, it will be a good start to you...

    [VBA]Sub test()
    Dim icol As Integer
    Dim iUsedNumbers(1 To 20) As Integer
    Dim irow As Integer
    Dim i As Integer
    Dim iTemp As Integer
    Dim bInArray As Boolean


    Randomize 'need this to ensure numbers are really random.

    For icol = 0 To 3
    For irow = 1 To 20

    ' check to see if the rnd number has already been used.
    Do
    bInArray = False
    iTemp = (Rnd() * 20) + 1 'get random number 1 - 20
    For i = 1 To 20
    If iUsedNumbers(i) = iTemp Then bInArray = True
    Next i
    Loop Until bInArray = False
    ' put number in cell
    Sheets("Serie 3").Cells(irow + 3, 4 + (icol * 13)) = iTemp
    ' add number to used numbers array
    For i = 1 To 20
    If iUsedNumbers(i) = 0 Then
    iUsedNumbers(i) = iTemp
    i = 20
    End If
    Next i
    Next irow
    'Clear usedNumbers Array
    For i = 1 To 20
    iUsedNumbers(i) = 0
    Next i
    Next icol

    End Sub[/VBA]

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by JB_Belgium
    What I asked was a new assigned ticket in sheet 3 (col D, Q, AD, Q)
    Available tickets in column A (sheet 3)
    The tickets (col A) can be different in each sheet
    That is not what you asked for initially. Your initial post whilst it included an annexed file ( and you need to remember here that some people never open files from others), did not include that you wanted a new assigned ticket in Sheet 3.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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