Hello experts,
I have a list of dates and I only need the month of each date. I am still learning on VBA so please bear with me. Below is the code I have written but it seems that it is only extracting the month of the first cell. Where have I done wrong? Also, I may need to increase the maximum number of i from 20 to 50 (or to infinity) if there are more new items in column B. Is there any way to improve the code? My concern is that if i were to increase to say 5000, the VBA would loop forever.
Dim m As Range
Dim i As Integer
Dim intMonth As Integer
Dim intDay As Integer
For Each m In Range("B3", Range("B3").End(xlDown))
intMonth = DatePart("m", Range("B3"))
intDay = DatePart("d", Range("B3"))
For i = 3 To 20
Cells(i, "D").Value = intMonth
Next i
Next m
Thank you
I have a list of dates and I only need the month of each date. I am still learning on VBA so please bear with me. Below is the code I have written but it seems that it is only extracting the month of the first cell. Where have I done wrong? Also, I may need to increase the maximum number of i from 20 to 50 (or to infinity) if there are more new items in column B. Is there any way to improve the code? My concern is that if i were to increase to say 5000, the VBA would loop forever.
Dim m As Range
Dim i As Integer
Dim intMonth As Integer
Dim intDay As Integer
For Each m In Range("B3", Range("B3").End(xlDown))
intMonth = DatePart("m", Range("B3"))
intDay = DatePart("d", Range("B3"))
For i = 3 To 20
Cells(i, "D").Value = intMonth
Next i
Next m
Thank you