Hello,
I write next code to copy active sheet, is working but:
- i need to: - switch it in ActiveSh, new created copy;
- counting cell A14 start from 1. to 999. on each copy;
- counting cell D16 start from 001 to 999 on each copy;
- counting of sheet is not properly with my needs, i use CoreSh name but i need to be same like cell D14( i can pass over this, is just a "view" problem);
Thank you in advance for your help!
I write next code to copy active sheet, is working but:
- i need to: - switch it in ActiveSh, new created copy;
- counting cell A14 start from 1. to 999. on each copy;
- counting cell D16 start from 001 to 999 on each copy;
- counting of sheet is not properly with my needs, i use CoreSh name but i need to be same like cell D14( i can pass over this, is just a "view" problem);
Thank you in advance for your help!
Code:
Public Sub SheetCopy()
Dim Sh As Worksheet, TemplateSh As Worksheet
Dim ShNum As Integer, HighestNum As Integer
Dim SheetCoreName As String
' INDICATE THE CORE SHEET NAME
SheetCoreName = "000"
' INDICATE THE SOURCE SHEET
Set TemplateSh = Sheets("000")
' DETERMINE NEXT NUMBER FOR SHEET
For Each Sh In Worksheets
If InStr(1, Sh.Name, SheetCoreName) = 1 Then
ShNum = Val(Right(Sh.Name, Len(Sh.Name) - Len(SheetCoreName)))
If ShNum > HighestNum Then HighestNum = ShNum
End If
Next Sh
' COPY TEMPLATE
TemplateSh.Copy after:=Sheets(Sheets.Count)
' MAKE VISIBLE
ActiveSheet.Visible = xlSheetVisible
' RENAME
ActiveSheet.Name = SheetCoreName & HighestNum + 1
End Sub