Forum Discussion
KristelNulens
Sep 26, 2022Copper Contributor
Deleting records from Excel through a macro
Hi, I'm new to VBA and macros and need some help with the following: I'm trying to delete all records from an Excel file that have the value '1601200-001' in the first column. I put in the be...
HansVogelaar
Sep 26, 2022MVP
If you want to delete in a loop, you should loop backwards, otherwise you may skip records as you have found:
Dim r As Long
For r = 3000 To 1 Step -1
If Range("A" & r).Value = "1601200-001" Then
Range("A" & r).EntireRow.Delete
End If
Next r
Assuming that A1 won't contain the value 1601200-001, the following should be faster:
Range("A1:A3000").AutoFilter Field:=1, Criteria1:="1601200-001"
Range("A2:A3000").EntireRow.Delete
Range("A1:A3000").AutoFilter- KristelNulensOct 21, 2022Copper ContributorThank you Hans for helping me out with this! This very simple piece of code will save me a ton of work! 🙂