Object Variable or with variable not set

  • Hi
    I have made a few cosmetic changes to an excel user form that was working perfectly. The changes were only very minor and related to removal of some of the options in the drop down menus.

    Now when I click the "open form" button i get a runtime error 424 object required.

    Ill paste all my code below in the hope that someone can spot what I've done wrong.

    When I click on Debug the "VolOrgs.Show" bit of code is highlighted in yellow.

    Sheet 2

    MODULE 1

    'Opens form and unprotects the worksheet
    Sub OpenForm()
    End Sub

    MODULE 2


    Private Sub CommandButton1_Click()
    Unload Me
    End Sub
    Private Sub UserForm_Click()
    End Sub

    FORM VolOrgs

    Any help with this will be much appreciated


  • Re: Object Variable or with variable not set

    The times I've had a similar problem is when I've deleted something on a form or changed its name, thereby leaving a bit of orphaned code in the form module. Are you sure you didn't do something like that? Check each sub in the form module and ensure its parent control is still on the form with the same name.

    It would help if, in that situation, the debug showed which sub was orphaned, but instead it show at the form.show line as in your case.

  • Re: Object Variable or with variable not set


    Add Option Explicit to the top of your userform code module and then run your code. If there is anything that has not be declared or references to controls that no longer exists the compiler will tell you.


  • Re: Object Variable or with variable not set

    Thanks guys,

    Derk you were right about me leaving some "orphaned" code in there after my edit.

    And Andy thanks I hadnt thought of putting Option Explicit in there, that saved me ages trawling through the code.

    Thanks to you both!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!