PDA

View Full Version : [SOLVED] I am looking to see if there is a more efficient way to write a code



spittingfire
05-23-2015, 02:22 PM
Hi All,

I am looking for a more efficient and quicker way to achieve what I am looking for. The below code works well but is rather slow when I have lots of data. Basically what I am doing is looking for a match from one sheet (Error Report) to another (Sheet1) and if a match is found the entire row in Sheet1 is deleted.



Sub removeErrors2()
Dim LR As Long, i As Long
With Sheets("Sheet1")
LR = .Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
If IsNumeric(Application.Match(.Range("K" & i).Value, Sheets("Error Report").Columns("M"), 0)) Then .Rows(i).Delete
Next I
End With
End Sub

Thanks for any help you can provide.

SamT
05-23-2015, 03:42 PM
First, you're in the testing forum where all posts are meaningless, so if someone does happen to be here, they aren't going to bother looking at any other threads.

Second, you put html code tags around your code, so it doesn't even look like VBA code. The pound (#) sign is the VBA Code icon.

Sub removeErrors2()
Dim LR As Long, i As Long
With Sheets("Sheet1")
LR = .Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
If IsNumeric(Application.Match(.Range("K" & i).Value, Sheets("Error Report").Columns("M"), 0)) Then .Rows(i).Delete
Next I
End With
End Sub

Third, your code looks pretty efficient to me.

Fourth, as a moderator, I get notified of all new posts, no matter where.