CDate - Outputting List of Dates 00:00:00

joey01_

New Member
Joined
May 10, 2022
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
Hi guys,

I'm trying to write some code to output a set of payment dates starting from a set start date. Term is the number of years the payment schedule goes on for and the frequency is the number of payments a year. Whenever I run this code 00:00:00 get outputted as the first date Any ideas why this happens? Thanks





Book1
ABC
1
2
3
40:00:00D0_1/1/22
51/6/22
61/12/22Term20
71/6/23Frequency2
81/12/23
931/05/2024
1029/11/2024
1130/05/2025
121/12/25
131/6/26
141/12/26
151/6/27
161/12/27
171/6/28
181/12/28
191/6/29
2030/11/2029
2131/05/2030
2229/11/2030
2330/05/2031
241/12/31
251/6/32
261/12/32
271/6/33
281/12/33
291/6/34
301/12/34
311/6/35
3230/11/2035
3330/05/2036
341/12/36
351/6/37
361/12/37
371/6/38
381/12/38
391/6/39
401/12/39
411/6/40
4230/11/2040
Sheet1


VBA Code:
Sub dates()


Dim dv() As Date
Dim i As Integer
Dim n As Integer
Dim D0_ As Date



D0_ = Range("C4")




n = Range("C6") * Range("C7")


ReDim dv(0 To n) As Date


With WorksheetFunction

For i = 1 To n

dv(i) = CDate(.WorkDay(D0_, .NetworkDays(D0_, .EDate(D0_, Round(i * 12 / Range("C7")) - 1))))
        Next i



End With



Range("A4:A" & UBound(dv) + 2) = Application.Transpose(dv)
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try changing your redim statement to start at 1 and not 0
eg.
VBA Code:
ReDim dv(1 To n) As Date
Your For loop is starting at 1 so dv(0) will be 0.

Also change your output line to this:
VBA Code:
Range("A4").Resize(UBound(dv)) = Application.Transpose(dv)

You could change the for loop but you will find it adds more complexity. (you would need to change: start & resize)
 
Last edited:
Upvote 0
Solution
Try changing your redim statement to start at 1 and not 0
eg.
VBA Code:
ReDim dv(1 To n) As Date
Your For loop is starting at 1 so dv(0) will be 0.

Also change your output line to this:
VBA Code:
Range("A4").Resize(UBound(dv)) = Application.Transpose(dv)

You could change the for loop but you will find it adds more complexity. (you would need to change: start & resize)
Ty Alex, works fine now
 
Upvote 0

Forum statistics

Threads
1,215,494
Messages
6,125,139
Members
449,207
Latest member
VictorSiwiide

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