I have a range of dates that i would like to separate, year, month and week number of those dates into different columns with VBA. For that I have used the following code, in fact I am calculating them cell by cell:
Sub Sortdata()
Dim WBData As Workbook
Dim Lastrow As Long
Dim j as long
Dim D as Date
Set WBData = ThisWorkbook
Lastrow = WBData.Sheets("CDR").Cells(Rows.Count, "A").End(xlUp).row
For j = 2 To Lastrow
D = WBData.Sheets("CDR").Cells(j, 5) 'date
WBData.Sheets("CDR").Cells(j, 19) = Year(D)
WBData.Sheets("CDR").Cells(j, 20) = Month(D)
WBData.Sheets("CDR").Cells(j, 21) = Application.WorksheetFunction.WeekNum(D)
Next j
End Sub
But sometimes the last row is very high over 1000 rows and it takes too much times. Do you have any idea How can i improve this code that it can run in short time?
Many Thanks for your help in advance!