Hi,
I'm trying to adapt some code I have copied to fit my needs. I want to delete all rows in a table which are equal to or less than a cell value in another sheet. The table will become larger over time. Obviously I am incompetent at vba so any help is much appreciated!
At the moment I have a 'compile error: Sub or function not defined' for the text 'worksheet'' in this line 'nm = Worksheet("SystemNames").Range("L2")'
Code
Sub DeleteOldData()
'
Application.ScreenUpdating = False
Dim tbl As ListObject, fld As Range, c As Range, nm As Long, i As Long, rws As Long
Set tbl = ActiveSheet.ListObjects("Records")
Set fld = tbl.ListColumns(5).DataBodyRange
Sheets("MyRecord").Select
rws = fld.Rows.Count
nm = Worksheet("SystemNames").Range("L2")
For i = 1 To rws
Set c = fld.Item(i)
If c.Value <= nm Then
c.EntireRow.Delete
i = i - 1
End If
Next i
Application.ScreenUpdating = True
Sheets("SystemNames").Select
End Sub
Display More