Consulting

Results 1 to 3 of 3

Thread: Solved: Need help with adding Next year's month

  1. #1
    VBAX Regular
    Joined
    Jun 2007
    Posts
    18
    Location

    Solved: Need help with adding Next year's month

    Hi, I recently discovered that the code below will not create new months for 2009. Can you help?


    Thanks.



    Sub AtCurrentMonthCreateNextMonth()
    Dim i As Long

    With ActiveWorkbook
    For i = 1 To 31
    'based on current month, creates and names new worksheets for each day of the Next month
    'also adds date to each form for every shift
    'e.g. in Feb, Apr
    If Month(DateSerial(Year(Date), (Month(Date) + 1), i)) <> (Month(Date) + 1) Then
    Exit For
    Else
    .Worksheets(1).Copy After:=.Worksheets(.Worksheets.Count)
    .ActiveSheet.Name = Format((DateSerial(Year(Date), (Month(Date) + 1), i)), "mmm d")
    Range("J1")(1) = Format((DateSerial(Year(Date), (Month(Date) + 1), i)), "mm/dd/yyyy")
    Range("J33")(1) = Format((DateSerial(Year(Date), (Month(Date) + 1), i)), "mm/dd/yyyy")
    Range("J66")(1) = Format((DateSerial(Year(Date), (Month(Date) + 1), i)), "mm/dd/yyyy")
    End If
    Next i
    End With
    End Sub

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub AtCurrentMonthCreateNextMonth()
    Dim i As Long

    With ActiveWorkbook
    For i = 1 To 31
    'based on current month, creates and names new worksheets for each day of the Next month
    'also adds date to each form for every shift
    'e.g. in Feb, Apr
    If Month(DateSerial(Year(Date), (Month(Date) + 1), i)) = (Month(Date) + 1) Or _
    (Month(Date) = 12 And Month(DateSerial(Year(Date), (Month(Date) + 1), i)) = 1) Then

    .Worksheets(1).Copy After:=.Worksheets(.Worksheets.Count)
    .ActiveSheet.Name = Format((DateSerial(Year(Date), (Month(Date) + 1), i)), "mmm d")
    Range("J1")(1) = Format((DateSerial(Year(Date), (Month(Date) + 1), i)), "mm/dd/yyyy")
    Range("J33")(1) = Format((DateSerial(Year(Date), (Month(Date) + 1), i)), "mm/dd/yyyy")
    Range("J66")(1) = Format((DateSerial(Year(Date), (Month(Date) + 1), i)), "mm/dd/yyyy")
    End If
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2007
    Posts
    18
    Location
    This works. Your time and efforts are appreciated.

    cgannm

Posting Permissions

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