Solved

EXCEL: Using a subroutine in several worksheets

Posted on 2013-01-07
6
241 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 47

Expert Comment

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

Accepted Solution

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

Expert Comment

by:Martin Liss
ID: 38752131
It would actually be better to put that sub in a code Module.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 47

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

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…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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