chesterrae
Board Regular
- Joined
- Dec 23, 2015
- Messages
- 51
I have found similar topic that deal with copying an entire sheet in one workbook and pasting it to a NEW sheet while the value on the specific cell increments and adds to the name of the new sheet created. However, the code provided was incomplete and missed the copying of the entire template sheet to new sheet. It only increments and rename the sheet created.
here's the given code:
Sub AddWs()
Dim i As Long, wsName As String, temp As String
Worksheets.Add after:=Worksheets(Worksheets.Count)
wsName = "App1"
If WorksheetExists(wsName) Then
temp = Left(wsName, 3)
i = 1
wsName = temp & i
Do While WorksheetExists(wsName)
i = i + 1
wsName = temp & i
Loop
End If
ActiveSheet.Name = wsName
ActiveSheet.Range("A1").Value = i
End Sub
Function WorksheetExists(wsName As String) As Boolean
On Error Resume Next
WorksheetExists = Worksheets(wsName).Name = wsName
On Error GoTo 0
End Function
Please help.
Thank you!
here's the given code:
Sub AddWs()
Dim i As Long, wsName As String, temp As String
Worksheets.Add after:=Worksheets(Worksheets.Count)
wsName = "App1"
If WorksheetExists(wsName) Then
temp = Left(wsName, 3)
i = 1
wsName = temp & i
Do While WorksheetExists(wsName)
i = i + 1
wsName = temp & i
Loop
End If
ActiveSheet.Name = wsName
ActiveSheet.Range("A1").Value = i
End Sub
Function WorksheetExists(wsName As String) As Boolean
On Error Resume Next
WorksheetExists = Worksheets(wsName).Name = wsName
On Error GoTo 0
End Function
Please help.
Thank you!