• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Code for Date as sheet name

Mariappan

New Member
Code:
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
ThisWorkbook.Worksheets("Master").Cells.Copy
ActiveSheet.Paste
Save
  ActiveWorkbook.SaveAs Filename:="X:\file06-21-2012\.xlsm", FileFormat _
  :=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
  'If data on this worksheet changes, refresh the pivot table
  Sheets("Pivot").PivotTables("PivotTable1").RefreshTable
End Sub
 
Last edited by a moderator:
Hi Mariappan

I have always espoused that if someone would please just post some code with one word - 'Fix' with some broken code or the workbook I would have more chance of solving their problem than a post resplendent with wordyness.

Here lives such and example.

I think this is what you are trying to do.

Code:
Sub testo()
Dim str As String

str = Format(Date, "dd-mm-yyyy")
Sheets.Add , Worksheets(Worksheets.Count)
ActiveSheet.Name = Format(Date, "dd-mm-yyyy")
Worksheets("Master").[a1].CurrentRegion.Copy [a1]
ThisWorkbook.RefreshAll
ActiveWorkbook.SaveAs "X:\file06-21-2012\" & str & ".xlsm"
End Sub

Take care

Smallman
 
Last edited:
@Smallman Sure, VBA is the language we all have in common, but honestly i do not like the attitude. Posting the code and not bothering to add few words to explain and ask for help... it's rude and offensive. Me/You/all the ppl here speading out useful comments/solutions, we're pleased to share the knowledge, but (as far as i am concerned) I do not like to be bullied into doing someone else' homework. Not saying this is the case, let's assume it's lack of experience for a newcomer ;)
 
Hai Guys,
Good Morning....
Sorry for my previous upload...... :confused::confused::confused:
what i thought to ask in that upload is "how to add calendar in that code instead of a date",
I'm new to this forum:rolleyes:. Anyway Sorry for the Inconvenience... Be Cool...... Cheers...:)
 
Back
Top