Hello,
Thanks to this forum I was able to get some working code to copy a template worksheet and rename them according to a list of names in a range. So, I changed my project a little and instead of a range I just want to use one cell. I thought I could adjust my code but for some reason it's not working.
So the sheet I want to copy is Sheet3 and what I want the name to be changed to will be in cell B7. I'm getting the error at the "If Contains" line. Thanks for anyone that can help me out.
Thanks to this forum I was able to get some working code to copy a template worksheet and rename them according to a list of names in a range. So, I changed my project a little and instead of a range I just want to use one cell. I thought I could adjust my code but for some reason it's not working.
Code:
Sub Button1_Click()
Dim numrows As Long, i As Long
Dim sname As String
With Sheet2
numrows = WorksheetFunction.CountA(.Range("B7"))
If numrows = 0 Then Exit Sub
For i = 1 To numrows
If Contains(Sheets, .Cells(i + 6, "B").Value) Then
sname = .Cells(i + 6, "B").Value
Call MsgBox(sname & " Sheet name already exists. Remove from List and try again", vbCritical, Application.Name)
Exit Sub
End If
ThisWorkbook.Sheet3.Copy After:=Sheets(Sheets.Count)
ThisWorkbook.Sheets(Sheets.Count).Name = .Cells(i + 6, "B").Value
Next
End With
End Sub<strike></strike>
So the sheet I want to copy is Sheet3 and what I want the name to be changed to will be in cell B7. I'm getting the error at the "If Contains" line. Thanks for anyone that can help me out.