+ Reply to Thread
Results 1 to 11 of 11

VB Drop down menu Code in module called from multiple Excel Sheets

  1. #1
    Registered User
    Join Date
    07-26-2010
    Location
    Hawaii
    MS-Off Ver
    Excel 2010
    Posts
    25

    VB Drop down menu Code in module called from multiple Excel Sheets

    I have an Excel Workbook with many sheets. I’m using a dropdown menu to navigate to each sheet based on the selection. What I would like to do is set this code in a module and call is from each page like so “Call Module1”. I keep getting this error when trying to call the module.

    Error: Expected variable or procedure, not module

    Name: ComboBox1_Change()

    Code In Module

    Please Login or Register  to view this content.
    I’ve tried renaming the combobox in the module to ComboBox and calling it.
    Call ComboBox
    I’ve tried calling the module
    Call Module1

    Thanks

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    Qualify the combobox's worksheet.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,750

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    You can't use a variable for a procedure name then call it.

    You also can't call a module.

    You can only call a procedure (Sub or Function) within a module.

    What exactly are you trying to call? What do you want to do that is different from what your code currently does?
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,750

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    Quote Originally Posted by AlphaFrog View Post
    Qualify the combobox's worksheet.

    Please Login or Register  to view this content.
    I am unclear on the question so I am unclear on this solution. If the Sub ComboBox1_Change is getting fired, then that means that the name ComboBox1 should be directly visible in the code module without having to qualify it with the sheet name. That is, this code must already be in Sheet1 so the qualification should be superfluous. Unless you are understanding the question in a way that I am not getting.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    Quote Originally Posted by 6StringJazzer View Post
    Unless you are understanding the question in a way that I am not getting.

    I read it as the OP moved the code to a standard module and is calling it like a regular procedure. If that's the case, the combobox's sheet needs to be qualified.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,750

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    Quote Originally Posted by AlphaFrog View Post
    I read it as the OP moved the code to a standard module and is calling it like a regular procedure. If that's the case, the combobox's sheet needs to be qualified.
    Aha. If that is the case then, I agree, and also the sub will have to be changed from Private to Public. The call from the sheets would be

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-26-2010
    Location
    Hawaii
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    What I’m trying to do is only call one piece of code from many pages(sheets). I’ve built a report navigation(drop down menu) on each sheet but I don’t want all that code on each sheet, the example I gave above is 4 of the 54 departments. Each sheet will have a drop down menu and I would like to call the module to trigger the drop down menu.

    Sheet2
    Call Module1.ComboBox1_Change
    Sheet3
    Call Module1.ComboBox1_Change
    Sheet4
    Call Module1.ComboBox1_Change
    Etc…

    Please Login or Register  to view this content.
    I qualified the code as you suggested but I get the following error now.

    Error: Subscript out of range

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-26-2010
    Location
    Hawaii
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    I think I need to pass a value from the comboBox1_Change on each sheet.

    Call Module1.ComboBox1_Change("1 Diamond Head")

    But can't get it to work.

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,120

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    try on each sheet
    Please Login or Register  to view this content.
    and then in a regular module
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-26-2010
    Location
    Hawaii
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    Thanks so much that works!

  11. #11
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,120

    Re: VB Drop down menu Code in module called from multiple Excel Sheets

    Glad to help & thanks for the feedback

+ 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. Replies: 5
    Last Post: 07-30-2018, 09:35 AM
  2. Drop down Menu across multiple sheets
    By Pragasen in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-25-2013, 09:41 AM
  3. Drop down menu across multiple sheets
    By Pragasen in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-19-2013, 10:58 AM
  4. Auto Drop Down Menu (what is it called)
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2013, 10:09 PM
  5. Drop down menu to populate multiple sheets
    By jerrett in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-12-2012, 09:01 AM
  6. Drop Down Menu list for multiple sheets
    By iamreese in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-02-2012, 11:10 AM
  7. code called from module check first data only not all of them
    By suny100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2011, 05:20 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