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:
But then Fluff posted with assurance that:
In response, I mentioned the following, to try to think of why Fluff mentioned "necessarily".
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.
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.
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:
and
And by the way, note that:
andVBA Code:Worksheets("sheet5")
are equivalent. (Just to shorten your code from here on out, if you want!)VBA Code:Sheets("sheet5")
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:
counts the number of both the Worksheets and chart sheets, whereas:VBA Code:MsgBox ThisWorkbook.Sheets.Count
gives you just the number of the Worksheets,VBA Code:MsgBox ThisWorkbook.Worksheets.Count
Worksheets vs Sheets - ExcelBaby
If you are a beginner of Excel VBA, you will be confused with Worksheets and Sheets. What is the difference between Worksheets and Sheets? Can they bewww.excelhowto.com
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)
VBA Code:
Sheets(sheetName)