Solved

Cannot call subs in different sheets

Posted on 2014-01-06
3
290 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 250 total points
ID: 39761311
Here is the syntax:

Application.Run "sheet2.SubS2"
0
 
LVL 51

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

728 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