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 ...
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.
Private Sub cmdOK_Click()
If IsEmpty(ActiveCell) = False Then
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
Private Sub PartListForm_Initialize()
txtPartNumber.Value = ""
txtCustomer.Value = ""
txtCustomerItemNumber.Value = ""
txtothercustitem.Value = ""
txtFilmType.Value = ""
txtFilmSize.Value = ""
txtFinishedRollSize.Value = ""
txtSleeveSize.Value = ""
txtMachineType.Value = ""
Private Sub cmdCancel_Click()
Private Sub cmdReset_Click()
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.)
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