Tic-Tac-Toe in Microsoft Excel? Let’s do it!

Simple TicTacToe Program

If you don’t have a Visual Basic Program (IDE) like VB6 or anything to build a program or software but you have only Microsoft Office (Excel) Application. Can we build such as this program the tic-tac-toe (as Bill Gates’ TicTacToe First Program)?

Well indeed, but here we have to learn coding of visual basic programming, of how we speak to computer using that language so that they can fully understand what’s our thought.

From this we just called the computer as a slave, because they always follow what our orders are

The exciting part here is you gonna build something that can be useful in our lives, in just easy way

So Let’s get started!

    1. Open up your Microsoft Excel
    2. Make sure the developer option is enabled. Please see the link
    3. You have to allow or enable the settings for macro to run the code
      • (File –> Option –> Trust Center –>Trust Center Settings –> Macro Settings –> Check “Enable all macros”)
    4. In the Developer Tab, click View Code
    5. Here we start writing the code, I shall provide you a simple code, for you to grasp easily
    6. Now from Insert Tab click Insert Form
    7. Change the Properties of the Form
Categorized View
      • Change the Name of the form to tttfrm
      • Change the Caption of the form to Tic-Tac-Toe
      • The Height and Width to 270, 300 respectively
      • To view Properties press F4
    1. Insert a CommandButton from toolbox (to show the tool box, in View Tab click Tool Box) to your UserForm (tttfrm)
    2. Click your CommandButton and change its property


    • Change the Caption to (blank) as in blank
    • Change the Height and Width to 55, 55
    • Change the Font Size to 22 (this is the size of our “O” and “X”)
  1. It should be like this.
  2. Copy this CommandButton to your UserForm (make 9 copies) form a tictactoe diagram.
  3. Press F5 to test your work
  4. Close it then click View Code, Double click the tttfrm
  5. Now for the coding, Double Click the first box or CommandButton1
  6. Insert this code within the sub:


    If CommandButton1.Caption = “” Then
        CommandButton1.Caption = “O”
    ElseIf CommandButton1.Caption = “O” Then
        CommandButton1.Caption = “X”
    Else: CommandButton1.Caption = “O”
    End If


  8. Do the rest, just copy the code and change it to CommandButton2.Caption for the right “Private Sub CommandButton2_Click()” then paste it within the sub
  9. Check it out! Run it (F5)
Wait! Something’s missing right? hmmm


Oh well, how can we restart the game, if there’s no restart button ( use instead the close button 🙂 )

Well it’s simple to handle this thing, just create another Command Button

Place the button inside your form

Double click the command and copy-paste this

    CommandButton1.Caption = “”
    CommandButton2.Caption = “”
    CommandButton3.Caption = “”
    CommandButton4.Caption = “”
    CommandButton5.Caption = “”
    CommandButton6.Caption = “”
    CommandButton7.Caption = “”
    CommandButton8.Caption = “”
    CommandButton9.Caption = “”

Run (F5)











Waaaiitt up! there’s more, well as you can see when you open your workbook, where is the button that direct you in your gameplay? Go in somewhere like View Code then find your UserForm and Run…….. It’s so hassle don’t you think?

Well Certainly, you can add up CommandButton within the sheet to navigate you faster to your gameplay, but how?

It’s easy , Go to the Developer Tab, Under the “Controls” Group, click Insert, Under Active X Controls, find the CommandButton

Right Click it ,click Property then change the Caption to TicTacToe

Double click your TicTacToe Button (note: the design mode must be enabled) to write down the code and copy-paste this


Close the coding window, and turn off the design mode

Click your TicTacToe Button!

Congratulations! You have created a simple TicTacToe Program in Microsoft Excel!

Next Stop, how will this program become like a True Executable Program using Microsoft Excel (tricky mimic)

Check out my New Excel Automated Data Entry Form v2.0

2 thoughts on “Tic-Tac-Toe in Microsoft Excel? Let’s do it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s