the following code checks if sheet named "Final"
exists, if yes it creates another worksheet but the name depends on the number of sheets in a workbook. So if there's only one sheet named "Final"
and 10 different sheets (altogether 11 sheets), the macro will add a new sheet named "Final_12"
.
How to amend the code so that it creates "Final_1"
, "Final_2"
ect. sheets?
Set WSF = wb.Worksheets.Add(After:=wb.Worksheets(PayrollWS))
Set NewSht = ActiveSheet
newShtName = "Final"
'if "Final" sheet exists, there will be another added, e.g. "Final_2"
For Each Sht In wb.Sheets
If Sht.Name = "Final" Then
newShtName = "Final" & "_" & wb.Sheets.Count 'how to amend this part?
End If
Next Sht
NewSht.Name = newShtName