What causes this runtime 424 "Object Required" error?

gers1978

Board Regular
Joined
Sep 9, 2014
Messages
74
I have some code and one of the subs contains this line:

Code:
Do Until Sheet1.Range("A" & Row).Value = vbNullString

It works flawlessly.

However I now want to run this code on a different sheet, namely one called "Invoice". So I changed the code too:

Code:
Do Until Invoice.Range("A" & Row).Value = vbNullString

However now when I run it, I get a runtime 424 error, "Object Required".

If I change it to:

Code:
Do Until Worksheets("Invoice").Range("A" & Row).Value = vbNullString

again, it works fine.

Can anyone tell me what's going on, and why sometimes you need to use "Worksheets("<name>")" format and sometimes not?

Thanks!

Also posted here: http://www.ozgrid.com/forum/showthread.php?t=197330&p=759134#post759134
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Sheet1.Range is an unnamed sheet, first in the book

Worksheets("Invoice")
identifies a sheet called Invoice

Invoice.Range would look for a named range called invoice

I use sheets("Invoice") normally, i don't know what the difference between sheets and worksheets actually is
 
Upvote 0
Look in the Project Explorer window. Under Microsoft Excel Objects, you will see a module called ThisWorkbook (unless you've changed the name) and a module for each worksheet. The worksheet names appear in the list as CodeName (SheetName). In a new workbook, it would appear as Sheet1 (Sheet1).

If you change the name of Sheet1 to Invoice, it would appear as Sheet1 (Invoice).

The construct Sheet1.whatever must use the codename of the worksheet. The construct Worksheets("Invoice") must use the sheet name.

@mole:

i don't know what the difference between sheets and worksheets actually is
The Sheets collection includes worksheet, chart sheets, macro sheets, and some other type of sheet I can't remember.
 
Upvote 0
The Sheets collection includes worksheet, chart sheets, macro sheets, and some other type of sheet I can't remember.

That's more understandable
 
Upvote 0
And Excel 95 modules.
 
Upvote 0
Is that different from XL4 macros sheets, Rory?
 
Upvote 0
Yep. It was the first VBA module.
 
Upvote 0
What's the XlSheetType enumeration?
 
Last edited:
Upvote 0
It doesn't have one. You add it using Modules.Add
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top