dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,362
- Office Version
- 365
- 2016
- Platform
- Windows
I have a button on my spreadsheet that copies a worksheet and pastes it in a new workbook. This is my code:
It was working before I added in the password protection. However, once I added it in, I started having all these problems. Is there a better way to do it?
I13 =CONCATENATE(F13," ",H13)
F13: has the month
H13: has the year
The sheet names are the format "mmmm yyyy"
I get the error subscript out of range and the protect line of code (the last line) is highlighted.
Code:
Private Sub cmdCopySheet_Click()
Worksheets("home").Unprotect Password:="costings"
Dim CopyMonth As String
CopyMonth = Range("I13").Value
Worksheets(CopyMonth).Activate
Worksheets(CopyMonth).Columns("A:E").copy
'Worksheets("home").Activate
Workbooks.Add
ActiveSheet.Paste
Worksheets("home").Protect Password:="costings"
End Sub
It was working before I added in the password protection. However, once I added it in, I started having all these problems. Is there a better way to do it?
I13 =CONCATENATE(F13," ",H13)
F13: has the month
H13: has the year
The sheet names are the format "mmmm yyyy"
I get the error subscript out of range and the protect line of code (the last line) is highlighted.
Last edited: