+ Reply to Thread
Results 1 to 4 of 4

Macro to create new worksheet

  1. #1
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379

    Macro to create new worksheet

    Hi guys,

    I need a macro to generate a new worksheet with the name one month after the last worksheet... i.e. I have worksheets called, January 2007, February 2007, March 2007, now I want a macro that will automatically create April 2007 and so on. It would be best if the worksheet could be a copy of another worksheet simply with a different name? Possible?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello ChrisMattock,

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    Wow, thanks that's awesome...
    Last edited by ChrisMattock; 01-30-2007 at 04:45 AM.

  4. #4
    Registered User
    Join Date
    01-19-2007
    Location
    Bangalore, India
    Posts
    66

    Re:

    Hi,

    It will work for you.

    Sub CreateNewMonth()
    Dim NewMonth, NewYear As Integer
    Dim NewSheetName As String
    Dim MonthName As String
    With ThisWorkbook
    oldmonth = .Worksheets(.Worksheets.Count).Name
    NewMonth = Month(DateSerial(Year(oldmonth), Month(oldmonth) + 1, 1))
    NewYear = Year(DateSerial(Year(oldmonth), Month(oldmonth) + 1, 1))
    If NewMonth > 12 Then
    NewYear = NewYear + 1
    NewMonth = 1
    End If
    NewSheetName = Choose(NewMonth, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") & " " & NewYear
    .Worksheets.Add After:=.Worksheets(.Worksheets.Count)
    With ActiveSheet
    .Name = NewSheetName
    End With
    End With
    End Sub

    Regards,
    Gajendra Gupta

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1