Error 424 - Object required

I have created an Userform on Excel (see codes below), when I run the macro to open the form I get a "Run-tim error '424': Object Required" even though I know the form is there. edit: Error happens on the macro, UserFrom3.Show. I double checked the form name and it is correct. Any thoughts?

Dim fecha As Date

fecha = Calendar1.Value
Call selectDate(unit, fecha)


End Sub

Private Sub Calendar1_Click()
Dim fecha As Date

fecha = Calendar1.Value
Call selectDate(fecha)

End Sub

Private Sub CommandButton1_Click()
Sheets("Summary").Activate
Unload Me
End Sub

Private Sub CommandButton3_Click()
Range("B3:J14").Select
Selection.ClearContents
Range("b3").Select
End Sub

Private Sub UserForm_Initialize()
With Application
'.ScreenUpdating = False
.EnableEvents = False
End With

Calendar1.Value = Date

End Sub

can you show us the code module where the error is occuring?  What exact line does the code stop on?

Thanks,

Eric

If this post is helpful or answers the question, please mark it so.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

The first thing you need to do is go into VBA, Tools menu, and choose Options. There, on the General tab, set Error Trapping to "Break In Class Module". When set otherwise, an error that occurs within an object module such as a Class or UserForm will flag the line of code that initialized the object. In your case, this is the UserForm3.Show line. Any error within the form will cause this line to be flagged as the line with the problem. If you use "Break In Class Module", you will be taken directly to the line of code within the object that caused the problem. You should ALWAYS have "Break In Class Module" in effect. There is no reason not to and using the other options can hide the real cause of the problem.

With "Break In Class Module" in effect, run your code to generate the error. Post the code highlighted by the debugger and other code related to that line that my be relevant.

 


Cordially, Chip Pearson Microsoft MVP, Excel Pearson Software Consulting, LLC www.cpearson.com
Cordially,
Chip Pearson
Excel MVP 1998 - 2014
Pearson Software Consulting, LLC
www.cpearson.com

6 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Sub CommandButton1_Click()
Columns("B:C").Select
Selection.EntireColumn.Hidden = False
Range("B3").Select
With Application
'.ScreenUpdating = False
.EnableEvents = False
End With
UserForm3.Show the code stop here

End Sub

Private Sub CommandButton2_Click()
Columns("B:C").Select
Selection.EntireColumn.Hidden = False
Range("B3").Select
Range("B3:J14").Select
Selection.ClearContents
Range("H1").Select
Selection.ClearContents
Range("b3").Select
End Sub

Private Sub CommandButton3_Click()
Columns("B:C").Select
Selection.EntireColumn.Hidden = True
UserForm5.Show
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

 

thanks so much for your help

End Sub

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I've changed the options and now the code stops here Calendar1.Value = Date

 

Private Sub UserForm_Initialize()
With Application
'.ScreenUpdating = False
.EnableEvents = False
End With

Calendar1.Value = Date

End Sub

i don't see anything wrong, do you?

thanks for your help

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Are you sure there is an object named "Calendar1" on the form?
If this post is helpful or answers the question, please mark it so.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Have you got Access installed on your computer? Did you create the Calendar object yourself or did you get all this from somewhere else and are trying to edit it to suit your particular purposes? Reason I ask is that I understand that the Calendar object is not available unless you have Access installed on your computer.

Having said that there are also a few other problems with your code. See the comments in the code below.

Private Sub CommandButton3_Click()
  'Need to specify required worksheet here
  With Sheets("Sheet1")   'Edit "Sheet1" to required worksheet
    '.Range("B3:J14").Select   'Don't need to select the range to clear
    .Range("B3:J14").ClearContents
    .Select   'Need to ensure worksheet is selected before selecting a range.
    .Range("b3").Select
  End With
End Sub

Private Sub UserForm_Initialize()
'If turning off events then need to turn back on again.
'Also need to ensure events get turned back on in event of error in code
'because they remain off until Excel re-starts or turned back on with code.

'Having said the above, the calendar should default to today's date without this code.

On Error GoTo ReEnableEvents

Application.EnableEvents = False

Calendar1.Value = Date

ReEnableEvents:
Application.EnableEvents = True

End Sub


Regards, OssieMac
Regards,

OssieMac

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thank you, thank you, thank you!!!!  you are a genius It worked I fixed the error and I can now open my form!!!!

Thank you!!!

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated March 3, 2023 Views 5,383 Applies to: