PC Review


Reply
Thread Tools Rate Thread

Calling routines from different sheets

 
 
Peter
Guest
Posts: n/a
 
      28th Oct 2009
I have a muti-sheet workbook with many macros on each sheet (i.e. not in
modules) and in userforms.
I need to be able to run a macro on one sheet then makes another sheet
active and then calls a macro stored in that sheet.

So Sheet1 has a number of buttons on it. One of them says "sort" and the
user presses this and the code behind the button runs. On Sheet2 there
are more command buttons and one of these says "check data". The plan is
that this button does some work then makes sheet1 active and then runs the
code under the commandbutton called "Sort". How do I make that happen.

Finally can you explain what is the difference/advantage of using Modules
to hold the code over having it in the sheets behind command buttons.

many thanks

Peter


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      28th Oct 2009
Without seeing the code behind the buttons, it would be difficult to give
advice on how to use the code from another sheet, because the code would
most likely run based on the sheet that contained the code. If you intend
to use code in more than one sheet or for more than one UserForm, you can
put it in the public module and then use the controls (buttons, forms, etc.)
to call the various procedures. For example:

In Sheet1 module:

Private Sub CommandButton1_Click()
Macro1
End Sub

In Sheet2 module:

Private Sub CommandButton1_Click()
Macro1
End Sub

In the public module:

Sub Macro1()
ActiveSheet.UsedRange.Sort Key1:=Range("A1")
End Sub

You can use the same macro by clicking either button if you want to sort
your used range on a sheet.


"Peter" <(E-Mail Removed)> wrote in message
newsp.u2hho8cz56zwdh@user-pc...
>I have a muti-sheet workbook with many macros on each sheet (i.e. not in
> modules) and in userforms.
> I need to be able to run a macro on one sheet then makes another sheet
> active and then calls a macro stored in that sheet.
>
> So Sheet1 has a number of buttons on it. One of them says "sort" and the
> user presses this and the code behind the button runs. On Sheet2 there
> are more command buttons and one of these says "check data". The plan is
> that this button does some work then makes sheet1 active and then runs the
> code under the commandbutton called "Sort". How do I make that happen.
>
> Finally can you explain what is the difference/advantage of using Modules
> to hold the code over having it in the sheets behind command buttons.
>
> many thanks
>
> Peter
>
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling external routines =?Utf-8?B?TWlrZQ==?= Microsoft Excel Programming 2 11th Dec 2006 09:57 AM
Using routines to change a number of sheets bestie Microsoft Excel Programming 8 27th Jul 2006 05:31 PM
Calling sub routines Andrew Microsoft Excel Programming 2 30th Jun 2005 05:30 PM
Calling LZO routines from VB.NET Paul Ferrill Microsoft VB .NET 3 10th Jan 2004 03:39 AM
Declaring in .Net an MSAccess Object and calling Sub routines in Access from .Net Gary O'Malley Microsoft C# .NET 0 4th Aug 2003 07:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:23 PM.