Solved

EXCEL: Using a subroutine in several worksheets

Posted on 2013-01-07
6
236 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
  • 4
  • 2
6 Comments
 
LVL 46

Expert Comment

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

Accepted Solution

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

Expert Comment

by:Martin Liss
ID: 38752131
It would actually be better to put that sub in a code Module.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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 46

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
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…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

791 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