Results 1 to 2 of 2

VBA "Run-time error '424': Object required

This is a discussion on VBA "Run-time error '424': Object required within the Excel Questions forums, part of the Question Forums category; This my first attempt writing code in Excel. I am stupmed on why when i press run sub while under ...

  1. #1
    New Member
    Join Date
    Dec 2009
    Location
    Idaho
    Posts
    2

    Default VBA "Run-time error '424': Object required

    This my first attempt writing code in Excel. I am stupmed on why when i press run sub while under forms the following code works but when i load it into Modules and run it I get "run-time error 424 object required"?
    I get the error on the bold text.

    Sub PartListForm()
    UserForm.Show
    End Sub
    Private Sub cmdOK_Click()
    ActiveWorkbook.Sheets("Part_List").Activate
    Range("a3").Select

    Do

    If IsEmpty(ActiveCell) = False Then
    ActiveCell.Offset(1, 0).Select
    End If
    Loop Until IsEmpty(ActiveCell) = True
    ActiveCell.Value = txtPartNumber.Value
    ActiveCell.Offset(0, 1) = txtCustomer.Value
    ActiveCell.Offset(0, 2) = txtCustomerItemNumber.Value
    ActiveCell.Offset(0, 3) = txtothercustitem.Value
    ActiveCell.Offset(0, 4) = txtFilmType.Value
    ActiveCell.Offset(0, 5) = txtFilmSize.Value
    ActiveCell.Offset(0, 6) = txtFinishedRollSize.Value
    ActiveCell.Offset(0, 7) = txtSleeveSize.Value
    ActiveCell.Offset(0, 8) = txtMachineType.Value
    Range("A3").Select
    End Sub
    Private Sub PartListForm_Initialize()
    txtPartNumber.Value = ""
    txtCustomer.Value = ""
    txtCustomerItemNumber.Value = ""
    txtothercustitem.Value = ""
    txtFilmType.Value = ""
    txtFilmSize.Value = ""
    txtFinishedRollSize.Value = ""
    txtSleeveSize.Value = ""
    txtMachineType.Value = ""
    txtPartNumber.SetFocus
    End Sub
    Private Sub cmdCancel_Click()
    Unload Me
    End Sub
    Private Sub cmdReset_Click()
    Call UserForm_Initialize
    End Sub

    Thanks

  2. #2
    Board Regular
    Join Date
    Feb 2003
    Location
    Luton, England.
    Posts
    8,115

    Default Re: VBA "Run-time error '424': Object required

    The code does not "know" where to look outside the form - so you need to be explicit, something like :-

    Userform1.txtPartNumber.Value = ""

    (it is not a good idea to use "reserved words" as variable names.
    ie. words that Excel uses already. In this case 'Userform' is an object type. We can often get away with it, but as a project grows the code can start giving errors.)
    Regards
    BrianB (using XL2003 & 2010)
    Most problems occur from starting at the wrong place.
    Use a cup of coffee to speed up all Windows processes.
    It is easy until you know how.
    **FORMATTED/COMMENTED CODE IS MORE LIKELY TO GET A REPLY

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com