JonRowland
Active Member
- Joined
- May 9, 2003
- Messages
- 415
- Office Version
- 365
- Platform
- Windows
I've had the following piece of code in procedure for a long time without any problem. However, all of a sudden the Set WkSheet entry is causing a 'Run Time Error "9': Subscript out of range'. I'm confused why.
What the code is doing is checking to see if a Worksheet call Data exsists and if so then to delete and so the code can procede, starting by adding a new WkSht of same name.
Any ideas why all of a sudden this would stop working? I'm running Excel version Microsoft 365 MSO (Version 2110 Build 16.0.14527.20234) 32-bit.
What the code is doing is checking to see if a Worksheet call Data exsists and if so then to delete and so the code can procede, starting by adding a new WkSht of same name.
Any ideas why all of a sudden this would stop working? I'm running Excel version Microsoft 365 MSO (Version 2110 Build 16.0.14527.20234) 32-bit.
VBA Code:
Dim WkSheet as WorkSheet
On Error Resume Next
Set WkSheet = Sheets("Data")
If WkSheet Is Nothing Then
' If WkSht doesn't exist then do nothing & continue procedure
Set WkSheet = Nothing
On Error GoTo 0
Else
' If exists then delete it
Sheets("Data").Delete
Set WkSheet = Nothing
On Error GoTo 0
End If
Sheets.Add.Name = "Data"