I am trying to set a worksheet variable using the worksheet CodeName property which is stored in a cell in the workbook. If I wanted to do this using the worksheet Name variable that is easy as evidenced by the code below, where the sheet Name is stored in cell A1.
If, however, I store the sheet CodeName in cell A1, then no matter what I try I cannot use it to assign a worksheet variable.
Any ideas are appreciated.
VBA Code:
Sub Test()
Dim ws As Worksheet
Dim sSheet As String
sSheet = [A1]
MsgBox Worksheets(sSheet).Name
End Sub
If, however, I store the sheet CodeName in cell A1, then no matter what I try I cannot use it to assign a worksheet variable.
Any ideas are appreciated.