I'm attempting to do the things written on this site www.excel-easy.com but when I click the commandbutton
(from ActiveX controls) in the worksheet just like what the website instructed, nothing happens. I tried to use a button from form controls, but it says that the error is in this
---> DinnerPlannerUserForm.Show
My Code:
Sub Button2_Click()
DinnerPlannerUserForm.Show
End Sub
When I used F8, it said the error is here --> Private Sub UserForm_Initialize()
Private Sub UserForm_Initialize()
'Empty NameTextBox
NameTextBox.Value = ""
'Empty PhoneTextBox
PhoneTextBox.Value = ""
'Empty CityListBox
CityListBox.Clear
'Fill CityListBox
With CityListBox
.AddItem "San Francisco"
.AddItem "Oakland"
.AddItem "Richmond"
End With
'Empty DinnerComboBox
DinnerComboBox.Clear
'Fill DinnerComboBox
With DinnerComboBox
.AddItem "Italian"
.AddItem "Chinese"
.AddItem "Frites and Meat"
End With
'Uncheck DataCheckBoxes
DateCheckBox1.Value = False
DateCheckBox2.Value = False
DateCheckBox3.Value = False
'Set no car as default
CarOptionButton2.Value = True
'Empty MoneyTextBox
MoneyTextBox.Value = ""
'Set Focus on NameTextBox
NameTextBox.SetFocus
End Sub
In rare cases, this error occurs when you have a valid object but are attempting to perform an invalid action on the object. For example, you may receive this error if you try to assign a value to a read-only property. Check the object's documentation and make sure the action you are trying to perform is valid.
Object Required in Excel VBA. Object required is an error which is caused at run time when we have defined any variable which is not an object but we try to assign some values using a SET statement. This error is a run time error that arises for various reasons.
This error can also occur when you remove or delete a textbox from your form, but forget to remove it from a line in initialization for eg:
Private Sub UserForm_Initialize()
CommandButton2.Enabled = False
TextBox4.Enabled = False 'textbox deleted from form
End sub
I'm assuming this issue has been resolved, but for anyone just now looking at it. I had this issue and it turned out to be that I had removed a ComboBox from my form, but it was still referenced in the code. Once I removed that section of the code, it worked beautifully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With