abhi221996
New Member
- Joined
- Sep 29, 2021
- Messages
- 35
- Office Version
- 365
- 2019
- Platform
- Windows
HOW CAN I GET THIS OUTPUT USING VBA?
Sub test()
Dim startD&, endD&, k&
startD = #12/15/2021#
endD = #12/31/2022#
For Each cell In Range("A4").Resize(endD - startD, 1)
k = k + 1
cell.Value = startD + k
Next
End Sub
Sub showDates()
Dim fromDate As Date, toDate As Date, myDate As Date
Dim rowno As Integer
rowno = 1
fromDate = #12/15/2021#
toDate = #1/10/2022#
myDate = fromDate
Do While myDate <= toDate
Worksheets("Sheet1").Cells(rowno, 1) = myDate
myDate = myDate + 1
rowno = rowno + 1
Loop
End Sub
Sub showDatesFor()
Dim fromDate As Date, toDate As Date, myDate As Date
Dim rowno As Integer
rowno = 1
fromDate = #12/15/2021#
toDate = #1/10/2022#
For myDate = fromDate To toDate
Worksheets("Sheet1").Cells(rowno, 1) = myDate
rowno = rowno + 1
Next
End Sub
Hi, "For Each" is one of "loop" but using specific object: "range"Thanks all the solutions.
is it possible to do it just by for loop.
For Each cell In Range("A4").Resize(endD - startD, 1)
k = k + 1
cell.Value = startD + k
Next
Sub showDates()
Dim fromDate As String, toDate As String
Dim rowno As Integer
fromDate = "12/15/2021"
toDate = "10/1/2022"
Worksheets("Sheet2").Cells(1, 2) = fromDate
For rowno = 1 To DateDiff("d", fromDate, toDate)
Worksheets("Sheet2").Cells(rowno + 1, 2) = DateAdd("d", 1, Sheets("Sheet2").Cells(rowno, 2))
Next
End Sub