date string as sheetname

  • Thread starter Thread starter keyser_Soze
  • Start date Start date
K

keyser_Soze

I have a macro that copies the last sheet to a new sheet at the end. I
would like to note the date that is in A2 prior to the copy, and add
one month to it.
This result will then become the name of the new sheet in the form
1-Oct-05 or something equivalent (ie: 1 Oct 05, 1Oct05,...)

How can I get the date from A2, and how can I modify it to the correct
string?

Thanks.
 
Hi Keyser,

Try:
'==================>>
Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim sStr As String
Dim i As Long

Set WB = ActiveWorkbook '<<======== CHANGE

i = WB.Sheets.Count

Set SH = WB.Sheets(I)

With SH.Range("A2")
sStr = DateSerial(Year(.Value), Month(.Value) + 1, 1)
End With

WB.Sheets.Add after:=SH
ActiveSheet.Name = Format(sStr, "d-mmm-yy")

End Sub
'==================>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top