Is there a way to indirectly reference a sheet by it's CodeName without looping through every sheet to test it's CodeName? For example,
Method 1: The following code does not work (would be ideal if it did though):
Dim ws As Worksheet
Set ws = "mySheet" & myVar
Method 2: But this works (if you hardcode the CodeName in):
Dim ws As Worksheet
Set ws = mySheetExample
Method 3: And this works (for a dynamic approach):
Dim ws As Worksheet
For Each sh In ThisWorkbook.Worksheets
If sh.CodeName = "mySheet" & myVar Then
'do something
End If
Next
which is a really long winded way of doing things, which brings me to my question, why does the first method not work?