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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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