VBA code for copy sheet

Gr33nMM

New Member
Joined
May 30, 2019
Messages
5
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!

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
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,213,506
Messages
6,114,025
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top