I have a workbook where I want to delete all rows in Sheet "Paste MyStock" column A that don't contain a date and then paste a formula and autofill to the last row.
The code works, however, it won't go through all rows. It suddenly stops after 2-3 rows and I have to run the macro several times. Why is this and how do I fix it?
This is my code:
Sub del_row_not_date()
Dim i As Integer
Dim MyStock As Worksheet
Dim Pivot As Worksheet
Dim Dta As Worksheet
Set MyStock = Sheets("Paste MyStock")
Set Formula = MyStock.Range("O1")
Set PasteFormula = MyStock.Range("N2")
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
LastRow = MyStock.Cells(MyStock.Rows.Count, "A").End(xlUp).Row
For i = 2 To LastRow
If IsDate(MyStock.Cells(i, 1)) = False Then
MyStock.Cells(i, 1).EntireRow.Delete
End If
Next
Formula.Copy
PasteFormula.PasteSpecial xlPasteAll
PasteFormula.AutoFill Destination:=MyStock.Range("N2:N" & LastRow)
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub