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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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