Populate Dates in different cells between date range - VBA

  • I am stuck at a point where I have a date range and need to populate the dates between that date range in different cells.


    E.g.: A1 shows 04/01/2015 and B1 shows 04/05/2015. Result should be starting from C1 to populate 04/01/2015, C2 as 04/02/2015, C3 as 04/03/2015 and so on..


    The date range can go upto 100 days and to repeat this activity until the last row with date of the sheet.


    Any help will be much appreciated. I have attached a spreadsheet for your reference and workings.


    Cheers
    RP

  • Re: Populate Dates in different cells between date range - VBA


    VBA?

    Code
    Sub test()
        Dim x
        x = DateDiff("d", [a1], [b1]) + 1
        With Range("c1")
            [a1].Copy .Cells
            .AutoFill .Resize(, x)
        End With
    End Sub
  • Re: Populate Dates in different cells between date range - VBA


    Admin <> can u pls delete this post.. I guess I posted incomplete request


    Thanks

  • Re: Populate Dates in different cells between date range - VBA


    Quote from RP_1985;757874

    Admin <> can u pls delete this post.. I guess I posted incomplete request


    Thanks


    What's the problem?

  • Re: Populate Dates in different cells between date range - VBA


    The request was incomplete.. Since you have already provided the response, just want to check one more thing.. Can I get the similar result for multiple line items (like Vlookup way).. Below is what I am actually trying to achieve (spread sheet attached)..


    Data:
    [TABLE="width: 565"]

    [tr]


    [td]

    Employee ID

    [/td]


    [td]

    Product

    [/td]


    [td]

    From

    [/td]


    [td]

    To

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [TD="align: right"]11709
    [/TD]

    [td]

    Apple

    [/td]


    [TD="align: right"]4/3/2015
    [/TD]
    [TD="align: right"]4/5/2015
    [/TD]

    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [TD="align: right"]12094
    [/TD]

    [td]

    Orange

    [/td]


    [TD="align: right"]4/15/2015
    [/TD]
    [TD="align: right"]4/16/2015
    [/TD]

    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [TD="align: right"]11709
    [/TD]

    [td]

    Apple

    [/td]


    [TD="align: right"]4/29/2015
    [/TD]
    [TD="align: right"]4/30/2015
    [/TD]

    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [TD="align: right"]12094
    [/TD]

    [td]

    Orange

    [/td]


    [TD="align: right"]4/18/2015
    [/TD]
    [TD="align: right"]4/20/2015
    [/TD]

    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    Result

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [TD="align: right"]11709
    [/TD]

    [td]

    Apple

    [/td]


    [TD="align: right"]3-Apr
    [/TD]
    [TD="align: right"]4-Apr
    [/TD]
    [TD="align: right"]5-Apr
    [/TD]
    [TD="align: right"]29-Apr
    [/TD]
    [TD="align: right"]30-Apr
    [/TD]
    [TD="align: right"][/TD]

    [/tr]


    [tr]


    [TD="align: right"]12094
    [/TD]

    [td]

    Orange

    [/td]


    [TD="align: right"]15-Apr
    [/TD]
    [TD="align: right"]16-Apr
    [/TD]
    [TD="align: right"]18-Apr
    [/TD]
    [TD="align: right"]19-Apr
    [/TD]
    [TD="align: right"]20-Apr
    [/TD]

    [td][/td]


    [/tr]


    [/TABLE]

  • Re: Populate Dates in different cells between date range - VBA


    Try

  • Re: Populate Dates in different cells between date range - VBA


    When I go to the below step, I am getting Type mismatch error..


    x = DateDiff("d", a(i, 3), a(i, 4)) + 1

  • Re: Populate Dates in different cells between date range - VBA


    When I am trying to repeat the same activity until the last active cell of column B using below code, I am getting result only for first row and then it just loop without populating any result from row 2.


  • Re: Populate Dates in different cells between date range - VBA


    I have attached the spreadsheet with what result I am getting with code below and what I am expecting..
    # of rows is not limited and can very each time. Sorry for the confusion..


  • Re: Populate Dates in different cells between date range - VBA


  • Re: Populate Dates in different cells between date range - VBA


    Thanks.. Awesome that works for me, but got stuck with one more last thing..


    If the dates are same in cell a1 and b1, I should be getting the first date but it is giving me runtime error. Attached spreadsheet with the code..

  • Re: Populate Dates in different cells between date range - VBA


    How do I eliminate weekends from the summary that shows up in sheet2. E.g.: in attached sheet I got date range from 16-Nov to 23-Nov for all Type. When I run the macro in sheet2 I am getting 16-Nov, 17-Nov, 18-Nov, 19-Nov, 20-Nov, 21-Nov, 22-Nov, 23-Nov


    I do no need weekends and but should show only 16-Nov, 17-Nov, 18-Nov, 19-Nov, 20-Nov, 23-Nov


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!