+ Reply to Thread
Results 1 to 3 of 3

VBA Random Generator

  1. #1
    Registered User
    Join Date
    03-22-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    1

    VBA Random Generator

    Hello I hope you guys can help with this.
    I have this program written in VBA:

    Function GetFive()
    Dim iNum As String
    Dim iNum2 As String
    Dim strNum As String
    Dim i As Integer
    Dim j As Integer
    Dim Counterko As Integer
    Dim checker(1 To 5) As String
    Counterko = Int((22 * Rnd) + 1)
    iNum = "A" & Counterko
    strNum = Worksheets("Sheet1").Range(iNum).Value
    iNum2 = iNum
    For i = 1 To 5
    strNum = Trim(strNum & " " & strNum2)
    'MsgBox (strNum)
    checker(i) = iNum2
    ' MsgBox ("i=" & i & "iNum2=" & iNum2)
    Counterko = Int((22 * Rnd) + 1)
    iNum2 = "A" & Counterko
    For j = 1 To i
    If iNum2 = checker(j) Then
    i = i - 1
    strNum2 = ""
    Exit For
    Else
    iNum = iNum2
    strNum2 = Worksheets("Sheet1").Range(iNum2).Value
    End If
    Next j
    Next i

    Now I need to add a code that chooses a number between first number 1-17, second number 4-30, third number 12-42, fourth number 28-52 and fifth number 38-56 and it would give me a 15 group of numbers. I also would like to add the "click" button. I'm not realy good in doing this kindna stuff I just combined what i found in the internet but I can't seem to find this one. Oh I am trying to do a lotto program. Thanks in advance.

  2. #2
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: I need your help in VBA Random Generator

    You need to wrap your code with the code tags.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA Random Generator

    How to add CODE tags is explained in the forum rules.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

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