Delete all rows that match the cell value simultaneously with command button

  • Hello there !!!


    Sorry I am posting all my questions here, just that I find that in this forum people are more responsive :) I have this code that works, but not the way I want it to. I want the loop to delete all the rows that match the cell value with the click of the button. At the moment I have to click through and they delete one by one with each click. Is there a way that it can just go over the work Sheet and delete at the same time ???


    Thank youuu in advance !!!

  • Possibly...

    If I've been helpful, let me know. If I haven't, let me know that too. 

  • Re: "Sorry I am posting all my questions here...."

    Why? I am sure everyone here is glad to see you here. Don't be shy. Come back anytime.


    The code from dangelor has you covered and is faster also.


    In your code, if you change this

    Code
    i = 1
    Do While ws.Cells(i, 3) <> ""

    to this

    Code
    For i = LastRow To 1 Step - 1    '<----- When deleting, always start from the end.

    and

    Code
    i = i + 1
    Loop

    to this

    Code
    Next i

    You would have had a home run.


    You could also have the three lines from If to End If in a single line like so

    Code
    If ws.Cells(i, 3).Value = student Then  ws.Cells(i, 3).EntireRow.Delete


    But stick to dangelor's code as that is the way to go.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!