+ Reply to Thread
Results 1 to 4 of 4

Call sub from multiple worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    07-04-2022
    Location
    USA
    MS-Off Ver
    MS 365
    Posts
    2

    Question Call sub from multiple worksheets

    Hi,

    I'm new to VBA. I'm trying to call a Sub from two different worksheets of the same workbook, but I'm getting an error. Here's what I have.

    In Modules -> Module1 I have:

    Public Sub ABC()
      MsgBox "You are here"
    End Sub
    In Microsoft Excel Objects -> Sheet1 I have:
    Public Sub CommandButton1_Click()
    Call ABC
    End Sub
    In Microsoft Excel Objects -> Sheet2 I have:
    Public Sub CommandButton1_Click()
    Call ABC
    End Sub
    When I click the button while on Sheet 1, it works. When I click the button while on Sheet 2, I get "Compile error: Sub or function not defined." Is there a way to get this to work? Thanks!
    Last edited by Peppermint Pizza; 07-05-2022 at 02:54 PM.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,944

    Re: Call sub from multiple worksheets

    Hi and welcome to the forum

    Could you attach the file so we can see it in context? Easier to diagnose these issues when we can poke around the file, especially when there looks to be little wrong with the code example above.

    EDIT:
    Attached is a file I set up exactly as you describe in your post, and all seems to work fine for me...

    BSB
    Attached Files Attached Files
    Last edited by BadlySpelledBuoy; 07-04-2022 at 05:22 PM.

  3. #3
    Registered User
    Join Date
    07-04-2022
    Location
    USA
    MS-Off Ver
    MS 365
    Posts
    2

    Re: Call sub from multiple worksheets

    Thank you, BadlySpelledBuoy. I figured out the problem. It was a typo. The original code used a name other than ABC, and there was a typo on Sheet 2. Once I knew from your reply that this should work, I was able to find the problem.

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,944

    Re: Call sub from multiple worksheets

    Glad I could help point you toward the issue, and happy you managed to resolve it

    BSB

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Can you group worksheets together, and call upon them all at once within a VBA code?
    By sy898661 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-05-2019, 03:18 PM
  2. Replies: 0
    Last Post: 01-28-2015, 08:49 AM
  3. [SOLVED] VBA to Call Multiple Macros
    By Pierce Quality in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 01-03-2014, 11:39 AM
  4. Replies: 1
    Last Post: 07-26-2013, 11:20 PM
  5. Use dropdown list to call worksheets in a workbook
    By shoro in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-09-2012, 09:45 PM
  6. [SOLVED] Call macro in worksheets on opening workbook
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-02-2012, 08:04 PM
  7. Call A Macro From Every Worksheets
    By lotus1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-12-2009, 02:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1