Sub Rnd_N_REP()
Dim myrange As Range, rr, cc, pp As Integer
rr = [B2]: cc = [B1]
pp = rr * cc + 1
' Range("C3").SpecialCells (xlCellTypeLastCell)
Set myrange = Range("C3:E7")
myrange.ClearContents
myrange.Interior.ColorIndex = xlNone
Set myrange = Range("C3", [c3].Offset(rr - 1, cc - 1))
myrange.Interior.ColorIndex = 6
Randomize
For i = 0 To pp - 2
rw = i Mod rr + 3
If rr = cc Then cl = Int(i / cc) + 3 Else cl = i Mod cc + 3
10 x = Int(Rnd * pp)
For Each ce In myrange
If ce = x Or x = 0 Then GoTo 10
Next ce
Cells(rw, cl).Value = x
Next i
[c3].Select
End Sub