MS Excel: Unique random number generator within a range

How to use it

  1. Open Excel & VBA editor (Alt+F11)
  2. Insert the code below under Sheet1
  3. Go back to Excel and select your desired range to fill with random & non-repeating numbers
  4. Execute the macro (Alt+F8)

Sub randomNumbers()
    Low = Application.InputBox("Enter first valid value", Type:=1)
    High = Application.InputBox("Enter last valid value", Type:=1)
    Selection.Clear
    For Each cell In Selection.Cells
        If WorksheetFunction.CountA(Selection) = (High - Low + 1) Then Exit For
        Do
            rndNumber = Int((High - Low + 1) * Rnd() + Low)
        Loop Until Selection.Cells.Find(rndNumber, LookIn:=xlValues, lookat:=xlWhole) Is Nothing
        cell.Value = rndNumber
    Next
End Sub

Excel file to proof

I love those small and simple solutions so much


I thought I had an answer, but this was a dead end (but quite fun) and I don't know how to remove it. My need is to do bingo-sheets with random setups.

Make a column A4:A63 with the numbers 1 to 60. Enter a fairly big prime number less than 60 cell B1. For example '47`.

In B2 enter

=RANDBETWEEN(1;59)

In rows B4:B63 fill with

=MOD(((A4+B$2)*B$1);60)+1 
=MOD(((A5+B$2)*B$1);60)+1 
...
=MOD(((A63+B$2)*B$1);60)+1 

This will make a fairly random sequence. B$2 will only shift the sequence.