Tutorial : How create a simple Game with VBA Excel
Hi ladies and gentleman, meet me again.
Now I want to show you about tutorial how make a simple Spin Machine Game or Slot Machine Game with VBA Excel.
I hope this can help you for expanding nice game with VBA Excel.
Ok, we now to begin to create it
- Create 3 button with Developer and change name to PLAY, RESET and BANK.
- Make cells with following format, and input 0 to cells F1, J2 and B15
- Marge cells B4:D11, F4:H11 and J4:L11
- Increase font size on cells B4, F4 and J4 to 100 poin, Change font to type with you want, I choose ALGERIAN and Red font color
- Change Conditional formating to Color Scales with you want, I choose Red - Yellow Green color scales.
- Change Conditional formating to Icon Sets with you want, I choose to 3 Signs.
- Press Alt+F11 and then insert a modules
- Enter the following VBA code to make the Spin Machine :
Sub PLAY_Click()
Range("B4") = Int((7 * Rnd) + 1)
Range("F4") = Int((7 * Rnd) + 1)
Range("J4") = Int((7 * Rnd) + 1)
Range("J2").Value = Range("F1")
x = x + 1
Range("F1").Value = Range("F1").Value + x
y = Range("B4") & Range("F4") & Range("J4")
If y = "111" Then
Range("F1").Value = Range("F1") + y
MsgBox "BONUS Rp.111"
End If
If y = "222" Then
Range("F1").Value = Range("F1") + y
MsgBox "BONUS Rp.222"
End If
If y = "333" Then
Range("F1").Value = Range("F1") + y
MsgBox "BONUS Rp.333"
End If
If y = "444" Then
Range("F1").Value = Range("F1") + y
MsgBox "BONUS Rp.444"
End If
If y = "555" Then
Range("F1").Value = Range("F1") + y
MsgBox "BONUS Rp.555"
End If
If y = "666" Then
Range("F1").Value = Range("F1") + y
MsgBox "BONUS Rp.666"
End If
If y = "777" Then
Range("F1").Value = 1000000 + y
MsgBox "LUCKY SEVEN ! YOU WINNER !!!" & vbNewLine & "YOUR WIN MONEY : Rp. 1.000.000"
End If
End Sub
Sub BANK()
Range("B15").Value = Range("B15") + Range("F1")
MsgBox "SAVE YOUR MONEY TO BANK, SUCCESS !"
x = 0
Range("F1").Value = x
Range("B4").Value = 0
Range("F4").Value = 0
Range("J2").Value = 0
Range("J4").Value = 0
End Sub
Sub start()
x = 0
Range("F1").Value = x
Range("B4").Value = 0
Range("F4").Value = 0
Range("J2").Value = 0
Range("J4").Value = 0
Range("B15").Value = 0
End Sub
- Function button :
- Button SPIN to randomise slot machine
- Button RESET for Start to Beginning Game
- SAVE to Saving your money
- Enjoy play game :)
So tutorial by me, don't forget your vote for me hopefully can be developed to be better and see you again :)
Good post
Thank you @taqdirul94 nice comment
Congratulations @khaidir22! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Congratulations @khaidir22! You received a personal award!
Click here to view your Board