Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Question on how to fill a range of dates on Excel (newer version).?

Update:

I know how to do basic data fills on Excel but I was wondering if it's possible to format it in a way that it will recognize a pattern if I'm trying to fill in weeks instead of days. Let me give an example:

April 24 - April 30

May 1 - May 7

May 7 - May 13

... Fill

... Fill

... Fill

June 26 - July 2

If that's not making sense please say so and I'll try to explain in a different way.

1 Answer

Relevance
  • 5 years ago

    I think you will have to resort to using VBA to do as you wish as your examples do not represent date formats Excel can parse.

    Here is one way to do that using a Worksheet_BeforeDoubleClick event handler. This assumes the column to contain the data is column A. If your column is not column "A", then modify the code before copying:

    Change the "A:A" reference to your column letter, i.e. "C:C", "M:M", etc.

    Change the "A" reference to your column letter, i.e. "C", "M", etc.

    Then, copy the event handler to the clipboard (highlight the entire event handler, right click inside the highlighted area, and 'Copy'):

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Range("A:A").ClearContents

    setWeeks = InputBox("Enter the number of weeks to display", "How Many?")

    If setWeeks = "" Then

    Target.Offset(1).Select

    Exit Sub

    End If

    stDate = InputBox("Enter the first date, i.e. '4/24/2016", "Starting Date")

    If stDate = "" Or Not IsDate(stDate) Then

    Target.Offset(1).Select

    Exit Sub

    End If

    sDate = CDate(stDate)

    For i = 2 To setWeeks + 1

    eDate = DateValue(sDate + 6)

    Range("A" & i).Value = sDate & " - " & eDate

    sDate = eDate + 1

    Next i

    Target.Offset(1).Select

    End Sub

    Select the worksheet that you wish to enter the dates into and right click the sheet tab at the bottom.

    Select 'View Code'.

    Paste the event handler into the white editing area to the right (right click inside the area and 'Paste').

    Close the VBE (Red button - top right).

    To set the dates, double click any cell in the worksheet. Enter the number of 'week periods' that you wish to enter, i.e. 10, 20, etc. and click 'OK'. Enter the starting date, i.e. 4/24/2016 and click 'OK'. That number of week dates will be returned. The dates will begin in row 2, assuming you have a column header in row 1.

Still have questions? Get your answers by asking now.