olorin_117
New Member
- Joined
- Jan 19, 2022
- Messages
- 18
- Office Version
- 2019
- Platform
- Windows
Hello
I have this code below that copies the entire sheet, renames the new one with the current date and erases the contents of certain range that works perfectly if I just run the macro. Now i would like that to work with the Workbook_NewSheet function in the workbook section of vba but all it does is. a) creates a new blank sheet with the name "Sheet2", creates another sheet with todays's date but doesn't copy anything, just a blank sheet. Am I doing something wrong?
P.S. Pretty newbie with VBA
I have this code below that copies the entire sheet, renames the new one with the current date and erases the contents of certain range that works perfectly if I just run the macro. Now i would like that to work with the Workbook_NewSheet function in the workbook section of vba but all it does is. a) creates a new blank sheet with the name "Sheet2", creates another sheet with todays's date but doesn't copy anything, just a blank sheet. Am I doing something wrong?
VBA Code:
Public Sub CopyRenameSheet1()
ActiveSheet.Copy Before:=ActiveSheet
Range("B9:H" & Range("B9").End(xlDown).Row).ClearContents
Range("B5").ClearContents
ActiveSheet.Name = Format(Date, "DD.MM.YYYY")
End Sub
P.S. Pretty newbie with VBA