Some further modifications below with my usual style of using plenty of validation on all-the-things-that-can-and-might-go-wrong.
but in the above post should the basic problem is in the
With Sheets("sName") line, which should be amended to
With Sheets(sName) to use the variable properly.
I think I prefer to create the sheet first, then hard-copy the values, on the premise that we don't need to have to formulas on the new sheet and copying them first might create a recalc (but I don't know - possibly and probably Excel is smart enough to know that these "new formulas" don't introduce any changed values so the difference might in fact be of no consequence).
Also, if we change the sheet name we should make sure it is a valid name. The way I have written this the code would still succeeds with the copying, but would fail to actually change the sheet name (so I guess I don't actually trust 99% of Excel users to always provide valid, non-duplicate sheet names, although they might do so 99% of the time).
Code:
Public Sub SaveCount()
Dim sName As String
Dim i As Integer
Dim wsOld As Worksheet
Dim wsNew As Worksheet
Application.ScreenUpdating = False
i = ActiveWorkbook.Worksheets.Count
sName = Application.InputBox("Enter a name for the new sheet", "Add sheet")
'No Name provided so user must have cancelled.
If sName = "" Then
Exit Sub
End If
'Name given but name is already being used for another worksheet
If WorksheetExists(ActiveWorkbook, sName) Then
MsgBox ("Error: Worksheet with name " & sName & " already exists.")
Exit Sub
End If
'Sheet to copy is worksheets(2) (this is dangerous since it is hardcoded and worksheet order can be changed by users)
Set wsOld = Worksheets(2)
'Create New Sheet
Set wsNew = Worksheets.Add(After:=Worksheets(i))
'Hardcopy all values from old sheet to new sheet
wsOld.Cells.Copy
wsNew.Cells.PasteSpecial xlPasteValuesAndNumberFormats
'Rename new worksheet (with error handling in case user has supplied an invalid name)
On Error Resume Next
wsNew.Name = sName
wsNew.Cells(1, 1).Select 'make it pretty - otherwise whole sheet is still selected
On Error GoTo 0
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
Public Function WorksheetExists(ByRef wb As Workbook, ByVal wsName As String) As Boolean
Dim s As String
WorksheetExists = False
On Error GoTo ErrExit:
s = wb.Worksheets(wsName)
WorksheetExists = True
ErrExit:
End Function