How do I add a tab using vba in excel that has both a name i specify and a date stamp

187 views Asked by At

I see how to add a tab for a macro with a date stamp but I have not been able to figure out how to also add a label to it as well. As an example I would like to be able to create a tab that says Dec-2016 Journal or Dec-2016 Log

2

There are 2 answers

1
mojo3340 On

Use this as a starting base

Option Explicit
Sub addsheet()

Sheets.Add
ActiveSheet.Name = "Insert Name"

End Sub

Do you need it to be self-allocating with respect to date/name etc?

0
KyloRen On

Try this, This will add the sheet and name it with a date log. I have put in more info on the date, as it could cause a conflict with same names for the sheet by making a new sheet in the same month

sName = "My Sheet"
With ThisWorkbook
   .Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = _
       sName & " " & Format(Now(), "mmm-yyyy hh-mm-ss")
End With

You can change the formatting to suit your needs. And if you don't need hours , minutes and seconds, just remove that from the formatting code.