+ Reply to Thread
Results 1 to 10 of 10

Macro to Auto Fill Dates in Column

Hybrid View

erock24 Macro to Auto Fill Dates in... 01-14-2009, 11:18 AM
ExcelFed If you use this formula in I7... 01-14-2009, 11:35 AM
erock24 Thank you for the reply. The... 01-14-2009, 02:37 PM
VBA Noob This worked for me. Note... 01-14-2009, 02:59 PM
erock24 That works perfect thank you.... 01-14-2009, 03:11 PM
VBA Noob If you are satisfied with the... 01-14-2009, 03:11 PM
erock24 How could I edit the macro to... 01-23-2009, 03:03 PM
erock24 How do I make it always... 01-23-2009, 07:48 PM
erock24 Re: Macro to Auto Fill Dates... 01-26-2009, 10:10 AM
erock24 Re: Macro to Auto Fill Dates... 01-26-2009, 12:02 PM
  1. #1
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Macro to Auto Fill Dates in Column

    I have a startdate F1 and an end date G1. Is there a macro that can list all dates by day within that range into column I7:down. A macro solution would be ideal.

    Thank you very much for your time and help.
    Last edited by erock24; 01-26-2009 at 12:03 PM.

  2. #2
    Registered User
    Join Date
    11-25-2008
    Location
    washington
    Posts
    24
    If you use this formula in I7 and drag down, it should work. This assumes I6 is blank

    =IF(I6="",G1-(G1-F1-1),IF(I6>=$G$1,"",I6+1))

  3. #3
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    Thank you for the reply. The formula works. However, I incorrectly stated my needs. Turns out I need to scratch the start date, end date stuff and proceed as described below:

    I need a macro that will identify the last cell in I and fill down the dates to the end of the year. For example, If the last cell in I were to be I188 and it = 6/30/2008, I need I189 to = 7/1/2008, I190 to = 7/2/2008, etc.

    Is there a macro that could do this?

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    This worked for me.

    Note no error checking if you run it twice

    Dim LastRow As Long
    Dim LastDate As Long
    LastRow = Cells(Rows.Count, "I").End(xlUp).Row
        With Cells(LastRow, "I")
            LastDate = DateValue("31/12/" & Year(.Value)) - .Value
            .AutoFill Destination:=Range("I" & LastRow & " :I" & LastRow + LastDate), Type:=xlFillDefault
        End With
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    That works perfect thank you. I added an error feature.
    Dim LastRow As Long
    Dim LastDate As Long
    LastRow = Cells(Rows.Count, "I").End(xlUp).Row
        With Cells(LastRow, "I")
            LastDate = DateValue("31/12/" & Year(.Value)) - .Value
    On error resume next
            .AutoFill Destination:=Range("I" & LastRow & " :I" & LastRow + LastDate), Type:=xlFillDefault
        End With
    Last edited by erock24; 01-14-2009 at 03:23 PM.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  7. #7
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    How could I edit the macro to only fill to the last day of the month instead of the year?

    Thank you.

  8. #8
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    How do I make it always default to the last day of the month. Instead of having the "31" hard coded in?

    Dim LastRow As Long
    Dim LastDate As Long
    LastRow = Cells(Rows.Count, "I").End(xlUp).Row
        With Cells(LastRow, "I")
            LastDate = DateValue("31/" & Month(.Value) & "/" & Year(.Value)) - .Value
    On Error Resume Next
            .AutoFill Destination:=Range("I" & LastRow & " :I" & LastRow + LastDate), Type:=xlFillDefault
        End With

  9. #9
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Re: Macro to Auto Fill Dates in Column


  10. #10
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Re: Macro to Auto Fill Dates in Column

    by jonmo1: http://www.mrexcel.com/forum/showthr...=1#post1816939

    Dim LastRow As Long
    Dim LastDate As Long
    LastRow = Cells(Rows.Count, "I").End(xlUp).Row
        With Cells(LastRow, "I")
        LastDate = (DateSerial(Year(.Value), Month(.Value) + 1, 1) - 1) - .Value
    On Error Resume Next
            .AutoFill Destination:=Range("I" & LastRow & " :I" & LastRow + LastDate)
        End With
    works perfect

+ 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