Solved

on click events in excel

Posted on 2013-05-31
8
193 Views
Last Modified: 2013-06-24
i have a calendar that i would like to reduce the lines of code for the onclick event similar to ms access onclick events eg,
Private Sub D1_Click(): Call BUTTON_CLICK("D1"): End Sub


for i=1 to 42
'the onclick procedure here to replace the private sub above


next
thanks
0
Comment
Question by:Svgmassive
  • 4
  • 2
  • 2
8 Comments
 
LVL 16

Expert Comment

by:Calvin Brine
Comment Utility
A couple of clairifications.

1.  Is your calendar an Excel Userform?  An ActiveX Control?  Is it embbed in your worksheet?
2.  I'm not sure what you are trying to accomplish with your loop?  Are you trying to call the button_click event 42 times?  

If you can provide some context on what you are trying to accomplish, we might be able to provide with what you want, or even something that might be even easier that you may not have thought of.

Cal
0
 

Author Comment

by:Svgmassive
Comment Utility
Userform
0
 
LVL 16

Expert Comment

by:Calvin Brine
Comment Utility
More.
0
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 500 total points
Comment Utility
I think you are asking about having a common error handler for multiple buttons, although you could be more forthcoming about your requirements.  What you want is not completely simple, but you can achieve it reasonable easily if you understand the principles.

Take a look at the attached example - you shold be able to adapt it to what you want.

You could also look at some articles, for example http://www.cpearson.com/excel/Events.aspx
event-handler-example.xlsm
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Svgmassive
Comment Utility
this is what's in code.i can eliminate this with a loop using the onclick event similar to ms access
Private Sub D1_Click(): Call BUTTON_CLICK("D1"): End Sub
Private Sub D2_Click(): Call BUTTON_CLICK("D2"): End Sub
Private Sub D3_Click(): Call BUTTON_CLICK("D3"): End Sub
Private Sub D4_Click(): Call BUTTON_CLICK("D4"): End Sub
Private Sub D5_Click(): Call BUTTON_CLICK("D5"): End Sub
0
 
LVL 17

Expert Comment

by:andrewssd3
Comment Utility
I don't understand what you're asking.  I have given you a working and tested example of how to do this flexibly.  You can do what you're suggesting if you really want to repeat the code 42 times.  If you want to do it with repetitive code like you suggest you could just have a trivial routine like
Sub Button_Click(byval sBtn as string)
            MsgBox "You clicked " & sBtn
End Sub

Open in new window

But I would imagine you could have worked this out by yourself.
0
 

Author Comment

by:Svgmassive
Comment Utility
i used th application caller method thanks
0
 

Author Closing Comment

by:Svgmassive
Comment Utility
excellent
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
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 simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now