I am trying to replace my worksheet function which generates a date for the first monday of the weekday when given a date. I have managed to create a VBA code that works to insert this function in to cells. It is very ugly and slow and may make some of you sick to your stomach. I was hoping someone could provide a more reasonable way for trying to accomplish this task.
'Insert Week Begin Formula into Column L
rw = 2
Do While Cells(rw, 1) <> ""
Cells(rw, 12) = "=IF($A2<>"""",DATE(YEAR($A2),MONTH($A2),DAY($A2)-WEEKDAY($A2,3)),"""")"
rw = rw + 1
Loop
'Copy the row references down for the Week Begin Formula
Dim LastRow As Long
LastRow = Cells(Rows.Count, "L").End(xlUp).Row
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L" & LastRow)
Bookmarks