Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 460
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 460
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time error '424': Object Required loren.pottinger Excel Programming 7 August 29th 06 03:16 PM
Runtime error '424': Object Required loren.pottinger Excel Discussion (Misc queries) 1 August 28th 06 09:56 PM
Run time error '424' object required Meltad Excel Programming 8 August 10th 06 09:34 AM
Excel 2007 Beta 2 - Macro Run-time error '424' Object required jcm21 Excel Programming 0 June 16th 06 07:17 PM
Run-time error '424': Object required Phil Bewig Excel Programming 3 February 1st 04 08:38 PM


All times are GMT +1. The time now is 04:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"