Share via

Sequential date over multiple tabs with macro

Anonymous
2014-12-04T18:38:35+00:00

I need create a spreadsheet with a sequential date over multiple tabs with macro in excel.

I need six tabs in the first tab the actual date and the next tabs with sequential dates.

I find this code but not work for me. 

Dim n As Integer

Dim i As Integer

Dim dt As Date

While Worksheets.Count > 1

    Application.DisplayAlerts = False

    Worksheets(2).Delete

    Application.DisplayAlerts = True

Wend

dt = Cells(1, 1).Value  '<==== Error in this line of code

n = DateSerial(Year(dt), Month(dt) + 1, 0) - dt + 1

Sheets(1).Name = Format(dt, "mmm dd yyyy")

For i = 2 To n

   Sheets.Add After:=Sheets(Sheets.Count)

   Sheets(i).Name = Format(DateAdd("d", 1, CDate(Sheets(i - 1).Name)), "mmm dd yyyy")

Next i

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2014-12-05T01:01:00+00:00

    Hi Mike,

    The code  send a runtime error Out of Range.

    Sub somesub()

    Dim x As Long

    For x = 1 To 6

        Sheets(x).Cells(1, 1) = (Date - 1) + x '<=== When I run the macro send an error in this line

    Next

    End Sub

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-12-04T19:33:34+00:00

    Hi,

    Try it this way.

    Sub somesub()

    Dim x As Long

    For x = 1 To 6

        Sheets(x).Cells(1, 1) = (Date - 1) + x

    Next

    End Sub

    Was this answer helpful?

    0 comments No comments