Automatically create a new sheet adding one digit to the total

BrianClough

New Member
Joined
Mar 30, 2016
Messages
19
Hi,

Due to the way Excel works out dates, 1900 onwards. My worksheet names are numbered for the serial number of the date, on the sheet itself I have an =MID to call the worksheet name, then I convert that in to a readable date in another cell.

This is probably a odd way of doing it, but I can't seem to get DATEVALUE to work, well, not the way I intend, and Excel won't allow you to use / in sheet names, so I found this way works best. (Unless anyone can advise me differently?)

Now, my other Excel users at work, are basic end users, they fill in boxes and we don't expect anything more than that.

The sheet needs to be duplicated at the start of the day.

Is there any way, I could implement a macro to automatically duplicate the last sheet, and add an extra digit to the total for the new sheet at all?

Regards,

Brian
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
The following will copy the active sheet and paste the contents to a new sheet that is added after all existing sheets.

I do not understand "add an extra digit to the total for the new sheet" .... ???

Code:
Option Explicit


Sub cpyTemplate()
Application.ScreenUpdating = False


    Columns("A:P").Select '<-- edit range here
    Selection.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Columns("A:P").Select
    ActiveSheet.Paste
    Range("B4").Select
    Application.Sheets((Sheets.Count) - 1).Select
    Range("B4").Select
    Application.CutCopyMode = False


Application.ScreenUpdating = True
End Sub
 
Upvote 0
Currently my sheets are named for the serial number of the date. 43440, being today. Tomorrow's will be 43441. This is what I meant by adding one digit to the total.

I'm using the serial format instead of an actual date, as when I am pulling the sheet name into a cell via formula:

=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)

This shows me the name, and then I convert it into a readable date in another cell, this then allows me to display different dates in other cells to my needs.

I don't seem to be able to put a ddmmyyyy into the sheet name, and using the =MID or =DATEVALUE, to be able to achieve the same result. I suspect I am doing something wrong.
 
Upvote 0
.
The following example presumes your serial date is located in A1. Rather than use a formula to create the next number, this macro adds one to the existing.

Code:
Sub cpyTemplate()


Application.ScreenUpdating = False


    Columns("A:P").Select '<-- edit range here
    Selection.Copy
    Range("A1").Select
    Sheets.Add After:=Sheets(Sheets.Count)
    Range("A1").Select
    ActiveSheet.Paste
    ActiveSheet.Range("A1").Value = ActiveSheet.Range("A1").Value + 1
    Range("A1").Select
    Application.CutCopyMode = False




Application.ScreenUpdating = True


End Sub
 
Upvote 0
Another way to go.

Code:
Dim Sheetname_ As String


Sheetname_ = ActiveSheet.Name
Sheetname_ = Sheetname_ + 1
    
Cells.Select
Selection.Copy
Sheets.Add After:=ActiveSheet
Cells.Select
ActiveSheet.Paste
ActiveSheet.Name = Sheetname_


End Sub
 
Upvote 0
Is there any way, this can rename the sheet, rather than changing the cells?

Sorry to be a pain

Regards,

Brian
 
Upvote 0
At risk of sounding cheeky, is there any way this could catch an error, and stop the process duplicating, if the user is already on a sheet, where that page has already been duplicated? To stop the function spitting out errors?

VBA is not a strength of mine.

Regards,

Brian
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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