Need a Macro to drive a "Helper Cell"

EE Pros,

I need a rather simple macro.  I need a macro that fires when you press the button and it produces a "1" or a "2" in the helper cell.

Sample attached.

Thank you in advance.

B.
Macro-for-Helper-Cell.xlsm
Bright01Asked:
Who is Participating?
 
Martin LissConnect With a Mentor Older than dirtCommented:
This is for single clicks.
Sub RoundedRectangle1_Click()
Static Toggle As Boolean
If Toggle Then
    Range("G8") = 2
    Toggle = False
Else
    Range("G8") = 1
    Toggle = True
End If
End Sub

Open in new window

0
 
Martin LissOlder than dirtCommented:
Sub RoundedRectangle1_Click()
Range("G8") = Int((2) * Rnd + 1)
End Sub

Open in new window

0
 
Martin LissOlder than dirtCommented:
The above will randomly show 1 or 2.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Martin LissOlder than dirtCommented:
You should also add this to the sheet code.
Private Sub Worksheet_Activate()
Randomize
End Sub

Open in new window

0
 
Bright01Author Commented:
Martin,

If I do not want random, but want press once I get 1, press again, I get 2.  Then I comment out the Private Sub..... right?

Also, if I want to make it a doubleclick..... is it double_click?

B.
0
 
Martin LissOlder than dirtCommented:
Please see my post above, and AFAIK there is no double-click for a shape. You'd need to use an ActiveX command button but that's usually not a good idea.
1
 
Bright01Author Commented:
It's a beautiful thing!  Thank you!

B.
0
 
Martin LissOlder than dirtCommented:
You're welcome and if you want to you can change it to this.
Sub RoundedRectangle1_Click()
Static Toggle As Boolean
If Toggle Then
    Range("G8") = 2
Else
    Range("G8") = 1
End If
Toggle = Not Toggle

End Sub

Open in new window

1
 
Bright01Author Commented:
Thank you Martin!  More then expected, as always!

B.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.