Consulting

Results 1 to 2 of 2

Thread: I am looking to see if there is a more efficient way to write a code

  1. #1

    I am looking to see if there is a more efficient way to write a code

    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.


    HTML Code:
    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.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •