Sunday, November 3, 2013

VBA: Simulasi Fungsi RND dan Nilai Acak pada Excel

Berikut adalah contoh animasi untuk mensimulasikan penggunaan nilai acak, contoh kode terlampir di bawah. Untuk diskusi lebih lanjut Anda dapat bergabung dengan user group Facebook kami (klik disini).


Sub Button1_Click()
    Sheet1.Range("A1") = "Rnd()"
    Sheet1.Range("B1") = "Rnd(0)"
    Sheet1.Range("C1") = ""
    Sheet1.Range("D1") = "Rnd(5)"
    Sheet1.Range("A2") = Rnd()
    Sheet1.Range("B2") = Rnd(0)
    Sheet1.Range("C2") = ""
    Sheet1.Range("D2") = Rnd(5)
End Sub

Sub Button2_Click()
    Sheet1.Range("A1") = "Rnd()"
    Sheet1.Range("B1") = "Rnd(0)"
    Sheet1.Range("C1") = "Rnd(-5)"
    Sheet1.Range("D1") = "Rnd(5)"
    Sheet1.Range("A2") = Rnd()
    Sheet1.Range("B2") = Rnd(0)
    Sheet1.Range("C2") = Rnd(-5)
    Sheet1.Range("D2") = Rnd(5)
End Sub

Sub Button3_Click()
    Sheet1.Range("A1") = "0.00 s/d 100.00"
    Sheet1.Range("B1") = "0 s/d 100"
    Sheet1.Range("C1") = "-50 s/d 50"
    Sheet1.Range("D1") = ""
    Sheet1.Range("A2") = Rnd() * 100
    Sheet1.Range("B2") = CInt(Rnd() * 100)
    Sheet1.Range("C2") = CInt(Rnd() * 100 - 50)
    Sheet1.Range("D2") = ""
End Sub

No comments:

Post a Comment