Sub Lottery_by_1_000_000_random_rows() ' You will need Excel 2007 or newer to run this macro, because it ' will make 1 000 000 lotteryrows to worksheet ' I suppose that you know enough of macros so you can run this one ' after running this macro, you have to do few things to its results ' 1) use Excels "Text to columns" - functionality to get numbers to four different columns ' 2) sort data according all four columns as you wish ' 3) use Excels "Remove duplicates" - functionality ' final ansver should be 58905 different rows with no duplicate values. ' ' this macro is quite slow. It took about 10 minutes to run with my laptop Dim IntFirst As Integer Dim IntSecond As Integer Dim IntThird As Integer Dim IntFourth As Integer Dim Result As String Dim X As Long Dim Y As Integer Dim Arr4Numbers(5) Columns("A:A").ClearContents Range("A1").Select ' This will take applications screenupdating off. So you can not see whats happening in a worksheet when macro ' is running ( only Statusbar is updated ). This makes makro run much faster. ' ' If you want you can "comment" that row and then you can see whats happening at worksheet. ' just add ' - mark at the beginning of next row ( ' Application.Screenupdating = False ) Application.ScreenUpdating = False For X = 1 To 1000000 ' lets make 1 000 000 rows ! ( you can put smaller value here if you think that 1000000 is too much ) ' for exsample "For X = 1 to 200000" ' FIRST NUMBER ( made by function RANDBETWEEN ) IntFirst = Application.WorksheetFunction.RandBetween(1, 36) Arr4Numbers(1) = IntFirst ' SECOND NUMBER ( just as before but we have to make sure that this number is not the same as first number ) ' Therefore code tries 10 times to pick appropriate number ( only if SecondNumber is same as FirstNumber ) IntSecond = Application.WorksheetFunction.RandBetween(1, 36) For Y = 1 To 10 If Not (IntSecond > 0 And IntSecond <> IntFirst) Then IntSecond = Application.WorksheetFunction.RandBetween(1, 36) End If Next Y Arr4Numbers(2) = IntSecond ' THIRD NUMBER IntThird = Application.WorksheetFunction.RandBetween(1, 36) For Y = 1 To 10 If Not (IntThird > 0 And IntThird <> IntFirst And IntThird <> IntSecond) Then IntThird = Application.WorksheetFunction.RandBetween(1, 36) End If Next Y Arr4Numbers(3) = IntThird ' FOURTH NUMBER IntFourth = Application.WorksheetFunction.RandBetween(1, 36) For Y = 1 To 10 If Not (IntFourth > 0 And IntFourth <> IntFirst And IntFourth <> IntSecond And IntFourth <> IntThird) Then IntFourth = Application.WorksheetFunction.RandBetween(1, 36) End If Next Y Arr4Numbers(4) = IntFourth ' This arranges the result numbers using worksheetfunction SMALL IntFirst = Application.WorksheetFunction.Small(Arr4Numbers, 1) IntSecond = Application.WorksheetFunction.Small(Arr4Numbers, 2) IntThird = Application.WorksheetFunction.Small(Arr4Numbers, 3) IntFourth = Application.WorksheetFunction.Small(Arr4Numbers, 4) ' This is finished ( ready ) row to be located to A-column later Result = IntFirst & " , " & IntSecond & " , " & IntThird & " , " & IntFourth ' This will tell you ( when macro is running ) how many "lottery rows" have been made Application.StatusBar = X & " lotteryrows done" ' This will write lotteryrows to worksheet to column A Range("A" & X).Value = Result Next X Application.StatusBar = "" End Sub Sub Lottery_only_results() ' you can check the result with Excels worksheetfunktion "COMBIN" ' formula is : =COMBIN(36,4) ' functions result will be : 58905 ' This means that there is 58905 different possible combinations of four digits when you use numbers from 1 to 36 ' ( combinations from 1,2,3,4 ; 1,2,3,5 ... to 33,34,35,36 ) ' ' running this macro will last less than 2 minutes Dim FirstNum As Integer Dim SecondNum As Integer Dim ThirdNum As Integer Dim FourThirdNum As Integer Dim RowCounter As Long Dim Result As String Columns("A:A").ClearContents Range("A1").Select RowCounter = 1 For FirstNum = 1 To 33 For SecondNum = FirstNum + 1 To 34 For ThirdNum = SecondNum + 1 To 35 For FourthNum = ThirdNum + 1 To 36 Result = (FirstNum & "," & SecondNum & "," & ThirdNum & "," & FourthNum) Range("A" & RowCounter).Value = Result RowCounter = RowCounter + 1 Application.StatusBar = RowCounter & " lotteryrows calculated" Next FourthNum Next ThirdNum Next SecondNum Next FirstNum Application.StatusBar = "" End Sub