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
Solved

Cannot call subs in different sheets

Posted on 2014-01-06
3
273 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
3 Comments
 
LVL 40

Accepted Solution

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

Application.Run "sheet2.SubS2"
0
 
LVL 50

Assisted Solution

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

You have to use the Sheet.CodeName

Maybe Sheet2.SubS2


Regards
0
 
LVL 15

Expert Comment

by:weinberk
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

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

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