How to count times I have clicked a shape?

4.2k Views Asked by At

I created a simple aim practice game, where you click on a circle that teleports when you click on it.

I want to count how many times you have clicked the circle.

2

There are 2 best solutions below

1
PeterT On

Add your shapes to a worksheet, then right-click and "Assign Macro". As an example, it can look like this:

enter image description here

Then your code in a VBA module catches the click events from the shapes (because you linked the shape to the macro in the previous step):

Option Explicit

Sub Oval1_Click()
    Dim countCell As Range
    Set countCell = ActiveSheet.Range("D7")
    countCell = countCell + 1
End Sub

Sub Oval2_Click()
    Dim countCell As Range
    Set countCell = ActiveSheet.Range("D7")
    countCell = 0
End Sub
1
Alvi On

You'll need to insert commandbutton from developer option and use that as shape. here is code that will count number of times it is clicked.

Private Sub CommandButton1_Click()
Static cnt As Long
cnt = cnt + 1
Me.CommandButton1.Caption = "I have been clicked " & cnt & " times"
End Sub