Solved

Need a Macro to drive a "Helper Cell"

Posted on 2016-07-29
9
17 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

803 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