+ Reply to Thread
Results 1 to 9 of 9

Module object error

Hybrid View

  1. #1
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Module object error

    Hi there,

    I got 6 worksheet and I a few userform.

    I tried to do this code:

    Sub DefineWorkSheet()
    
    Dim WS1 As Worksheet
    Dim WS2 As Worksheet
    Dim WS3 As Worksheet
    Dim WS4 As Worksheet
    Dim WS5 As Worksheet
    Dim WS6 As Worksheet
    
    Set WS1 = Worksheets("MonthSummary")
    Set WS2 = Worksheets("WeekSummary")
    Set WS3 = Worksheets("DatabaseForm")
    Set WS4 = Worksheets("DatabasePO")
    Set WS5 = Worksheets("Setup")
    Set WS6 = Worksheets("Products")
    
    End Sub
    And I call it in every userform header

    Call DefineWorkSheet
    However I got object error issue.

    Is it my method and approach wrong? I need this function to be working so every userform I only need to call the function instead of repeating the same code

    On the other hand if there is changes, I only change the function name instead of changing at every form.

    Any idea?

    Thank you.

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

    Re: Module object error

    Without you saying which error message you get exactly, or what line of the code it errors on, it's difficult to say exactly what's wrong.

    Check that the sheet names in your code are exactly what they are in the workbook. A trailing space on a sheet name would not be obvious to spot but would cause an error message if the code doesn't match.

    BSB

  3. #3
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: Module object error

    Hi BSB

    The error codei is Runtime Error 424
    Object Required

    The error come out when I run the userform

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

    Re: Module object error

    Could you attach the workbook here so we can have a look?

    BSB

  5. #5
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: Module object error

    New Book.xlsm

    Here you go, I already commented the error code area

    It's locate in module 2

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

    Re: Module object error

    The below code is causing the problem:

    For Each blah In [OutletList]
        Me.cmbOutlet.AddItem blah
    Next blah
    Excel doesn't know what "blah" is....

  7. #7
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: Module object error

    even I remove the code, the error is still at there

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

    Re: Module object error

    The problem was because you're declaring variables in a sub rather than making them Public (i.e. used in code outside of that sub).

    Have a look at the attached.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    63

    Re: Module object error

    yeah now it's work!

    thank you so much!

    +rep for your help

+ 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. Compile error in hidden module: Module 1 when workbook opened on different machine!?
    By MathUKTeacher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-06-2015, 04:38 PM
  2. [SOLVED] Compile error: Member already exists in an object module...Trying to create a form
    By MonaP92 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-12-2015, 11:12 AM
  3. [SOLVED] Member already exists in an object module form which this object module derives error
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2014, 03:14 AM
  4. [SOLVED] Code locks cells when inserted in sheet module but returns error in standard module
    By yoda66 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2014, 07:39 AM
  5. Replies: 3
    Last Post: 10-25-2011, 02:12 PM

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