[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Cannot call subs in different sheets

Posted on 2014-01-06
3
Medium Priority
?
299 Views
Last Modified: 2014-01-10
Hi All,

I am "self voting" this my most provincial question to date but I can't figure it out.  I have tried youtube and the usual places to get this kind of question asked.

I have a huge spreadsheet filled with VBA code from one end to the other.

In sheet19 I am trying to call a sub (not private) that is in sheet2.

My code goes something like this:

my sub()

'code here
'code here
'code here

call SubS2        'Sub from Sheet2 and it is not private so it should work

End Sub


So I know that I am doing something so silly that it hurts.

I have tried call sheet2.SubS2....and that does not work.

Any help is much appreciated.

Any cheap shots are surely warranted.   :)

thanks for your help!
0
Comment
Question by:BostonBob
[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
3 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1000 total points
ID: 39761311
Here is the syntax:

Application.Run "sheet2.SubS2"
0
 
LVL 53

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 1000 total points
ID: 39761317
Hi,

You have to use the Sheet.CodeName

Maybe Sheet2.SubS2


Regards
0
 
LVL 15

Expert Comment

by:Berkson Wein
ID: 39762274
Attach the workbook.

Not sure why you'd have code attached to every sheet, but it should still work.  I prefer to put nearly everything in modules, but that's just a preference.

I also suggest prefixing public functions with public, just for readability.


If in sheet1 you have

public function DoThisFromSheetOne()
    msgbox "From sheet 1"
end function

Open in new window


and in sheet 2 you have
public function CallTheThingFromOne()
     DoThisFromSheetOne
end function

Open in new window


if you fun CallTheThingFromOne, it should display "From Sheet 1" in a message box.

Test that out for us?

If that doesn't work, or if you need more help, attach a sample.
0

Featured Post

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!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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.

649 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