I'm using the following code that works well except that it also transfers the code behind the original Master worksheet with it to the newly added worksheet, as well as all the ActiveX controls (two command buttons).
This is not my desired outcome. I just want the data. I noticed that even using value = value still does not remove the code.
Can someone assist?
This is not my desired outcome. I just want the data. I noticed that even using value = value still does not remove the code.
Can someone assist?
VBA Code:
Sub CreateSheetWithName()
Dim ws As Worksheet
Dim sheetName As String
Set ws1 = ThisWorkbook.Sheets("Master")
sheetName = ws1.Range("A2").Value & "-" & ws1("Master").Range("E2")
For i = 1 To Worksheets.Count
If Worksheets(i).Name = ws1.Range("A2").Value & "-" & ws1.Range("E2").Value Then
End If
Next i
If Not exists Then
ws1.Copy after:=Worksheets(Sheets.Count)
Sheets(i).Name = sheetName
'ActiveSheet.Name = ws1.Range("A2").Value & "-" & ws1.Range("E2").Value ' accomplishes the same as the line above
Sheets(sheetName).Shapes("Rounded Rectangle 3").delete
End If
ws1.Activate
End Sub