user10554059
user10554059

Reputation:

How to count times I have clicked a shape?

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.

Upvotes: -1

Views: 4451

Answers (2)

Alvi
Alvi

Reputation: 105

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

Upvotes: 3

PeterT
PeterT

Reputation: 8557

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

Upvotes: 3

Related Questions