Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


on click events in excel

Posted on 2013-05-31
Medium Priority
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

Question by:Svgmassive
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
LVL 16

Expert Comment

by:Calvin Brine
ID: 39211700
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.


Author Comment

ID: 39211702
LVL 16

Expert Comment

by:Calvin Brine
ID: 39211716
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 17

Accepted Solution

andrewssd3 earned 2000 total points
ID: 39211796
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

Author Comment

ID: 39211820
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
LVL 17

Expert Comment

ID: 39211977
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.

Author Comment

ID: 39251226
i used th application caller method thanks

Author Closing Comment

ID: 39273308

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

730 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