2014. 7. 25. 00:33

로또 번호 생성기

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

난수를 쉽게 공부하자.

Sub 단추1_Click()

    makeNum = Cells(1, 2)

    If makeNum < 1 Then

        makeNum = 100

    End If

    i = 3

    Do While i < makeNum + 3

        Cells(i, 1) = i - 2

        

        j = 2

        Do While j < 8

            Cells(i, j) = Int((46 * Rnd) + 1)

            j = j + 1

        Loop

        

        '정렬하기

        Call sortNums(i, n)

        

        '중복찾기

        Call getSame(i, n)

        

        Cells(i, 8) = Cells(i, 2) & Cells(i, 3) & Cells(i, 4) & Cells(i, 5) & Cells(i, 6) & Cells(i, 7)

        i = i + 1

    Loop

End Sub

Function sortNums(i, n)

    Range(Cells(i, 2), Cells(i, 7)).Select

    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear

    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range(Cells(i, 2), Cells(i, 7)), _

        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

    With ActiveWorkbook.Worksheets("Sheet2").Sort

        .SetRange Range(Cells(i, 2), Cells(i, 7))

        .Header = xlGuess

        .MatchCase = False

        .Orientation = xlLeftToRight

        .SortMethod = xlPinYin

        .Apply

    End With

End Function


Function getSame(i, n)

    k = 2

    Do While k < 8

        If Cells(i, k) = Cells(i, k + 1) Then

            Cells(i, k) = Int((46 * Rnd) + 1)

            Call sortNums(i, n)

            Call getSame(i, n)

        End If

        k = k + 1

    Loop

End Function