Creating A list of Dates Using VBA

PatrickMilano21

New Member
Joined
Jun 17, 2015
Messages
10
Hi,


I am looking to create a macro with a list of Dates and Times. I want to be able to have the user input the start date and start time (Ex. 9/7/2014 14:00) and an end time (Ex. 12/5/2015 3:00) and have excel fill a column with the dates starting at the start time every hour until it reaches the end time. Please help!! THank you


Example: Col 1

Row1: 9/7/2014 14:00
Row2: 9/8/2014 15:00
Row3: 9/9/2014 16:00
etc
etc.
Last Row: 12/5/2015 3:00
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Code:
Public Sub ExtrapolateDates()
Dim vDate, vEndDate
    
'cell A1 = start date
'cell B1 = End date
vDate = Range("A1").Value
vEndDate = Range("B1").Value


Range("A2").Select
While vDate < vEndDate
   vDate = DateAdd("h", 1, vDate)
   ActiveCell.Value = vDate
   
   ActiveCell.Offset(1, 0).Select  'next row
Wend
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,449
Messages
6,159,931
Members
451,604
Latest member
SWahl

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