What's the difference(s) between using Sheets("Sheet1") vs Worksheets("Sheet1") in VBA?

cmowla

Well-known Member
Joined
Sep 21, 2021
Messages
536
Office Version
  1. 365
Platform
  1. Windows
Hi everyone. At the end of this post, I thought I was doing right by the the original poster by mentioning that he/she can reduce the quantity of code by mentioning:

And by the way, note that:
VBA Code:
Worksheets("sheet5")
and
VBA Code:
Sheets("sheet5")
are equivalent. (Just to shorten your code from here on out, if you want!)

But then Fluff posted with assurance that:
Also Sheets & Worksheets are not necessarily equivalent.


In response, I mentioned the following, to try to think of why Fluff mentioned "necessarily".
Unless someone is going to use them to do a Worksheet count:

Where:

VBA Code:
MsgBox ThisWorkbook.Sheets.Count
counts the number of both the Worksheets and chart sheets, whereas:

VBA Code:
MsgBox ThisWorkbook.Worksheets.Count
gives you just the number of the Worksheets,


yes, they are equivalent because you cannot name a chart sheet the same name as a Worksheet without Excel asking you if you want to embed the chart in the sheet that you want to move it to.

So unless I am missing something, for this purpose of passing something into it to get a sheet object, they are equivalent.

If I'm missing something, can you please explain what? (To eliminate confusion, as that seems to be your motivation for posting that response?)

But Fluff basically mentioned that the purpose of his/her post was to tell me that I was wrong but not tell me why, as it was off-topic.
My motivation was to point out the fact that you were making inaccurate & misleading statements.
And I stand by what I said Worksheets & Sheets are NOT necessarily the same.

Now let's wait for the OP to respond, rather than getting sidetracked.

Okay, fair enough. But now since it is on topic, can someone tell me what I'm missing? Clearly my above reasoning implies that if you are going to be looping through all Sheets in a Workbook, that will cause problems if you want to get a range from that Sheet.
VBA Code:
MsgBox Sheets("Chart1").Range("A1").Value

So the question is therefore, if you know that the code you write is referring to a Worksheet (and therefore sheetName that is passed is a Worksheet name . . . which fits the context of the "note" that I posted in that thread), what are the difference(s) between using:
VBA Code:
Worksheets(sheetName)
and
VBA Code:
Sheets(sheetName)
 
The only reason I have used them is for convenience; you automatically get a tab called "Chart1" so it is obvious it is a chart without renaming it. Also it is a full screen chart which I sometimes want, once again without resizing it on a worksheet
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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