Add code like this, that deletes values starting from the top of the sheet, leaving the header row and 300 rows of data on sheet Data. Start the code by calling CleanUp from the workbook open event, and call StopIt from the workbook before close event. The macro is run every 5 minutes, but you can change that to a longer time period if it doesn't bother you to have more data. You could really just do it every time you open the workbook, unless the workbook is never closed.
Option Explicit
Public NextTime As Date
Sub CleanUp()
NextTime = Now + TimeValue("00:05:00")
With ThisWorkbook.Worksheets("Data")
'Clear rows from bottom
'If Application.CountA(.Range("A:A")) > 301 Then
' .Range("A302", .Cells(.Rows.Count, "A").End(xlUp)).EntireRow.Delete
'End If
'Clear rows from top
If Application.CountA(.Range("A:A")) > 301 Then
.Range("A2").Resize(Application.CountA(.Range("A:A")) - 301).EntireRow.Delete
End If
End With
Application.OnTime NextTime, "CleanUp"
End Sub
Sub StopIt()
Application.OnTime NextTime, "CleanUp", schedule:=False
End Sub
Bookmarks