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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
All Courses

From novice to tech pro — start learning today.