Add new WorkSheet and Name it as Current Date
You always add new WorkSheets in your WorkBook. Sometimes it seems very boring to do it manually (specifically if you have multiple sheets to add).
A simple solution to avoide this boredome is to automate it.
I've written the VBA code to add a new WorkSheet at the end of WorkSheets and name it as current Date.
Steps:
1. Open a new file
2. Press Alt+F11 to open VBA editor
3. In the left navigation value select ThisWorkbook
4. In the editor window enter one of the code below (based on your requirement)
5. Close the VBA editor
6. Save the file as Macro Enabled File
7. Test with you inputs
Code:
1. Add this code if you just want to add a new WorkSheet
Sub AddSheet()
Sheets.Add , Worksheets(Worksheets.Count)
End Sub
2. Add this code if you want to add a new WorkSheet and name it as current Date
Sub SheetNameAsCurrentDate()
Dim SheetName As String
SheetName = Format(Date, "dd-mm-yyyy") 'Change the format as per your requirement
Sheets.Add , Worksheets(Worksheets.Count)
ActiveSheet.Name = SheetName
End Sub
3. Add this code if you want to check if a sheet already exists with the name as current Date, if not add a new sheet and name it as current Date.
Sub CheckAndAddSheetNameAsCurrentDate()
Dim SheetName As String
SheetName = Format(Date, "dd-mm-yyyy") 'Change the format as per your requirement
On Error GoTo AddNew
Sheets(SheetName).Activate
Exit Sub
AddNew:
Sheets.Add , Worksheets(Worksheets.Count)
ActiveSheet.Name = SheetName
End Sub
Below is the screenshot how the Date format will look like.
I think this has been informative and I thank you for viewing.
-Saurabh
Attachment | Size |
---|---|
AddNewSheet.xlsm | 14.72 KB |
- saurabhlakhanpal's blog
- Login or register to post comments
- 63192 reads
Recent comments
5 years 41 weeks ago
6 years 27 weeks ago
6 years 39 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 48 weeks ago
7 years 4 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago