Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

EXCEL: Using a subroutine in several worksheets

Posted on 2013-01-07
6
Medium Priority
?
253 Views
Last Modified: 2013-01-07
I would like place a subroutine in the workbook section of the workbook and use it in multiple worksheets.

In the General Section of the workbook code I have this:
Private Sub GlobalSub(str As String)
blah blah blah
End Sub

Open in new window


In the Click event of a combo box I have this:
Private Sub combobox1_Click()
ThisWorkbook.GlobalSub ("TEXT")
End Sub

Open in new window


I get a Method or Data Member not found error in line 2 of the click event.
Thoughts?
0
Comment
Question by:gpchicago08
[X]
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
6 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38752120
Change Private to Public
0
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 38752126
eg Public Sub GlobalSub(str As String)
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38752131
It would actually be better to put that sub in a code Module.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Closing Comment

by:gpchicago08
ID: 38752137
duh.
0
 

Author Comment

by:gpchicago08
ID: 38752163
wouldn't that be in the General section of the workbook?
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38752218
Again the best thing to do is to either cut and paste that sub (after changing to Public) to an existing code module (like Module1), or

Alt+f11 to get to the IDE
From the menu do Insert|Module
Paste or create a new Public sub

Having done that the code is available everywhere in the workbook.

In any case I'm glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

604 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