D1 hücresine üretmek istediğiniz rakamların naximum değerini yazınız. D2 hücresine ise kaç adet sayı üreteceğinizi yazınız.
Sub rastgele()
Dim i As Integer
Dim bul As Range
Randomize
If Range("D1").Value < Range("D2") Then
MsgBox "D1 hücresinin değeri D2 hücresinden küçük olmamalı"
Exit Sub
ElseIf Range("D1").Value = "" Or Range("D2") = "" Then
MsgBox " D1 VE D2 hücrelerine bir değer giriniz"
Exit Sub
End If
Cells(1, 1).Value = Int((Range("D1") * Rnd) + 1)
For i = 2 To Range("D2")
Cells(i, 1).Value = Int((Range("D1") * Rnd) + 1)
For Each bul In Range("A1:A" & Cells(i - 1, 1).Row)
If Cells(i, 1).Value = bul.Value Then
Cells(i, 1).Value = Int((Range("D1") * Rnd) + 1)
End If
Next bul
Next i
End Sub
Hiç yorum yok:
Yorum Gönder