Code to list all dates between a range

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have the following code but it doesn't stop looping until it runs out of columns. Please can someone modify it so it stops at the last date?
Code:
    FirstDay = Day(Range("StartDate"))
    LastDay = Day(Range("EndDate"))
    
    FirstMonth = Month(Range("StartDate"))
    LastMonth = Month(Range("EndDate"))
    
    FirstYear = Year(Range("StartDate"))
    LastYear = Year(Range("EndDate"))
    
    LastDate = DateSerial(LastYear, LastMonth, LastDay)
    
    .Cells(5, 3).Value = Range("StartDate")
    k = 4
    Do Until .Cells(5, k) >= DateSerial(LastYear, LastMonth, LastDay)
        DateStamp = DateSerial(FirstYear, FirstMonth, FirstDay + k - 3)
        .Cells(5, k).Value = DateStamp
        k = k + 1
    Loop

Thank you,
Jack
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Ignore, just realised the test condition part of my loop is in the wrong place
 
Upvote 0
Hi,:smile:

Hope you can help me on this !!

I need to know the dates in between the dates and the dates should be in separate rows

if the dates range is 2/2/2015 to 2/7/2015 then mystart is 02/02/2015 and myend is 02/7/2015

till myend reaches I need to insert a row and fill the dates from 2/2/2015 to 2/7/2015.

Like this I have many rows to be filled... I need to check the whole column and fill in the dates.

-sindhuja
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,718
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top