| 
    
     |  | 変数名に Item などは使わない方がいいです。 いちばん簡潔なコードで済むのは Dictionaryオブジェクト を使う方法ですが
 それは誰かがレスしてくれるでしょう。
 で、例えば Match関数 で重複チェックをする方法なら・・
 
 Sub 乱数A1()
 Dim a As Integer, b As Integer
 Dim c As Integer, d As Integer, e As Integer
 Dim i As Integer, MyV As Integer
 Dim RAry() As String
 Dim MyAry As Variant
 
 Cells.ClearContents
 a = 1  '乱数の下限
 b = 5  '乱数の上限
 c = 4  '乱数から取出す個数
 d = 0  '空白のセル数
 e = 1  '左からの列数
 If c > b - a + 1 Then Exit Sub
 ReDim RAry(c): RAry(0) = a - 1
 For i = 1 To c
 Do
 Randomize
 MyV = Int((b - a) * Rnd + a)
 Loop Until IsError(Application.Match(CStr(MyV), RAry, 0))
 RAry(i) = CStr(MyV)
 Next i
 MyAry = Filter(RAry, CStr(a - 1), False)
 Cells(d + 1, e).Resize(c).Value = _
 WorksheetFunction.Transpose(MyAry)
 Erase RAry, MyAry
 End Sub
 
 * Option Base 1 は削除して下さい。
 
 |  |