Consulting

Results 1 to 5 of 5

Thread: UserForm does not show ... Runtime error

  1. #1

    UserForm does not show ... Runtime error

    I created a UserForm and the following macro opens it:

    Sub DoMetrics()
    frmMetrics.Show
    End Sub

    This macro is placed in a module created in the Workbook. I placed a button on a worksheet (Sheet4) and assigned the above macro for that button.
    The UserForm opens when the button is actuated.

    I moved (cut and paste) the button to another worksheet (Sheet2) in the same workbook and reassigned the button to the same macro.
    When I actuate the button now, I get the following runtime error 1004:

    "Method of 'Range' of object '_Worksheet' failed."

    When I move (cut and paste) this button to the previous worksheet (Sheet4), it works again. There seems to be a reference to a Worksheet, but I am not able to understand it.

    As I understand, we have a module common to all worksheets and the macro should be available to the button from whichever worksheet it is placed.
    I'll appreciate if anyone explains to me what the problem is.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Sounds like your userform's code is the problem. Use Debug's F8 in that Sub to step line by line to see where the problem lies.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Or post a workbook with enough of the code that demonstrates the problem
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    I created another Test workbook with a UserForm with a button to open the Form moved from one worksheet to another.
    This works without problem.
    Obviously I have a problem in the Form_Initialize code or cod for other events. I'll check and come back if I cannot find the solution.
    Thanks for the help.

  5. #5
    I have a macro that sets the ranges from the data in the data worksheet. I am using the Cells notation for the ranges.
    When I am calling the macro from another worksheet, the Range is throwing an error as I did not include a period(.) before the Cells keywords.
    After correcting the code with periods, I could move the button to any worksheet and the Form works.

Posting Permissions

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