乱数でおみくじを作る

 

Sub test()

’ 乱数でおみくじを作る

    Const xlMini As Long = 0
    Const xlMax As Long = 7
    Dim myNum As Long

    Randomize  ’ 乱数系列を初期化

’    乱数 =Int((最大値 - 最小値+1) *Rnd + 最小値)
     myNum = Int((xlMax - xlMini + 1) * Rnd + xlMini)
 
    Select Case myNum
            Case 1
                MsgBox "ご運勢は、「一番:大吉」です", vbInformation
            Case 2
                MsgBox "ご運勢は、「二番:吉」です", vbInformation
            Case 3
                MsgBox "ご運勢は、「三番:半吉」です", vbInformation
            Case 4
                MsgBox "ご運勢は、「四番:小吉」です", vbInformation
            Case 5
                MsgBox "ご運勢は、「五番:末小吉」です", vbInformation
            Case 6
                MsgBox "ご運勢は、「六番:末吉」です", vbInformation
            Case 7
                MsgBox "ご運勢は、「七番:凶」です", 16
                
            Case Else
                MsgBox "神さま休息中で、あとでやり直してください。", vbInformation
    End Select

 

End Sub

 

 

― ― ― ― ― ― ― ― ― ― → Excel VBA基礎入門もくじ へ戻る 

 

参考記事