Solved

Need a Macro to drive a "Helper Cell"

Posted on 2016-07-29
9
18 Views
Last Modified: 2016-08-01
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
0
Comment
Question by:Bright01
  • 6
  • 3
9 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41734752
Sub RoundedRectangle1_Click()
Range("G8") = Int((2) * Rnd + 1)
End Sub

Open in new window

0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41734754
The above will randomly show 1 or 2.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41734854
You should also add this to the sheet code.
Private Sub Worksheet_Activate()
Randomize
End Sub

Open in new window

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Bright01
ID: 41734903
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
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41734939
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
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41734943
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
 

Author Closing Comment

by:Bright01
ID: 41735282
It's a beautiful thing!  Thank you!

B.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41735314
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
 

Author Comment

by:Bright01
ID: 41737354
Thank you Martin!  More then expected, as always!

B.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question