BobtBuilder
New Member
- Joined
- Sep 1, 2023
- Messages
- 45
- Office Version
- 365
- Platform
- Windows
Hi folks,
I am trying to create a generic code that could use the sheet name, which is stored in a cell.
Dim wsName As String
Dim ws As Worksheet
Dim targetCell As Range
' Set the target cell (N3 in this case) for the active sheet
Set targetCell = ActiveSheet.Range("N3")
' Get the value from the target cell
wsName = targetCell.Value
Set ws = ThisWorkbook.Sheets("wsName") ' Here is where I would like the name of the sheet to be, (wsname is correct) but cannot set ws, keep getting subscript out of range, but yet wsname is correct.
Please advise
I am trying to create a generic code that could use the sheet name, which is stored in a cell.
Dim wsName As String
Dim ws As Worksheet
Dim targetCell As Range
' Set the target cell (N3 in this case) for the active sheet
Set targetCell = ActiveSheet.Range("N3")
' Get the value from the target cell
wsName = targetCell.Value
Set ws = ThisWorkbook.Sheets("wsName") ' Here is where I would like the name of the sheet to be, (wsname is correct) but cannot set ws, keep getting subscript out of range, but yet wsname is correct.
Please advise