Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run-time error '424': Object Required
I have 2 userforms. The first opens just fine, the second gives me the
Run-time error. This is the code I'm using. How is one form different than the other? Sub Workbook_Open() ActiveSheet.Range("H15").Select If Selection.Value = "" Then UserForm1.Show Else UserForm2.Show End If |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run-time error '424': Object Required
The code you present looks OK. The problem lies within the code of the
Userform. In the VBA editor, go to the Tools menu, choose Options, then the "General" tab. There, in the "Error Trapping" section, choose "Break In Class Module". Save your workbook and re-open it. The code should enter debug mode on the exact line of code that is causing the problem. (If you don't have error trapping set to "Break In Class Module", debugging will stop on the line that instantiates a class -- your code's Show methods -- rather than on the line of code within the class that actually caused the error.) ActiveSheet.Range("H15").Select I wouldn't rely on that. When you save and close a workbook, it will re-open to the sheet and cell that was active when the workbook was saved. This may not be the sheet that you think it should be. Instead, do something like Worksheets("Sheet1").Select Worksheets("Sheet1").Range("H15").Select You can't just use Worksheets("Sheet1").Range("H15").Select alone because if Sheet1 isn't active, the code will fail. You must first Select a sheet before Selecting anything on that sheet. Or, much better, don't select anything at all. Get rid of the Select code and use: If Worksheets("Sheet1").Range("H15").Value = "" Then UserForm1.Show Else UserForm2.Show End If In this case, it doesn't matter what sheet happens to be active when the workbook is opened -- it will always test H15 on Sheet1. Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group, 1998 - 2009 Pearson Software Consulting, LLC www.cpearson.com (email on web site) On Wed, 27 May 2009 12:27:01 -0700, Doug wrote: I have 2 userforms. The first opens just fine, the second gives me the Run-time error. This is the code I'm using. How is one form different than the other? Sub Workbook_Open() ActiveSheet.Range("H15").Select If Selection.Value = "" Then UserForm1.Show Else UserForm2.Show End If |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run-time error '424': Object Required
Thanks for the info. The detailed explanation really helps an amature like me.
Thanks Doug "Chip Pearson" wrote: The code you present looks OK. The problem lies within the code of the Userform. In the VBA editor, go to the Tools menu, choose Options, then the "General" tab. There, in the "Error Trapping" section, choose "Break In Class Module". Save your workbook and re-open it. The code should enter debug mode on the exact line of code that is causing the problem. (If you don't have error trapping set to "Break In Class Module", debugging will stop on the line that instantiates a class -- your code's Show methods -- rather than on the line of code within the class that actually caused the error.) ActiveSheet.Range("H15").Select I wouldn't rely on that. When you save and close a workbook, it will re-open to the sheet and cell that was active when the workbook was saved. This may not be the sheet that you think it should be. Instead, do something like Worksheets("Sheet1").Select Worksheets("Sheet1").Range("H15").Select You can't just use Worksheets("Sheet1").Range("H15").Select alone because if Sheet1 isn't active, the code will fail. You must first Select a sheet before Selecting anything on that sheet. Or, much better, don't select anything at all. Get rid of the Select code and use: If Worksheets("Sheet1").Range("H15").Value = "" Then UserForm1.Show Else UserForm2.Show End If In this case, it doesn't matter what sheet happens to be active when the workbook is opened -- it will always test H15 on Sheet1. Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group, 1998 - 2009 Pearson Software Consulting, LLC www.cpearson.com (email on web site) On Wed, 27 May 2009 12:27:01 -0700, Doug wrote: I have 2 userforms. The first opens just fine, the second gives me the Run-time error. This is the code I'm using. How is one form different than the other? Sub Workbook_Open() ActiveSheet.Range("H15").Select If Selection.Value = "" Then UserForm1.Show Else UserForm2.Show End If |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Run-time error '424': Object Required | Excel Programming | |||
Runtime error '424': Object Required | Excel Discussion (Misc queries) | |||
Run time error '424' object required | Excel Programming | |||
Excel 2007 Beta 2 - Macro Run-time error '424' Object required | Excel Programming | |||
Run-time error '424': Object required | Excel Programming |