How to automatically delete certain rows in Excel?

Excel Macros: How do I delete Rows based on value in three columns?

  • I have an excel sheet that has 11 columns with rows until 2500. I am wanting to create a macro that will either automatically delete or a macro I can create a button to initiate that will delete every row that has a 0 in columns H (Inv), I (Sales) and (Sales2nd). A 0 has to appear in ALL THREE columns in order for me to want to delete it. I am very much so a beginner when it comes to macros and have only had success so far with sorting and deleting specific numbers of rows. So if anyone can help me get gain a little bit more knowledge that would be great! Thanks for all your help in advance!

  • Answer:

    Here's an easy macro to do it.  It works for VLOOKUP.  Check the variables at the top to make sure it fits your needs.  Also, this assumes there is continuous data in column A -- if there isn't, you can change the DO LOOP to a FOR LOOP and specify the rows you want to check over. Option Explicit ' Your sheet name Private Const SHEET As String = "Sheet1" ' Row in which data begins. Private Const ROW_DATA_START As String = 2 Public Sub RemoveRows() Dim row As Long Dim ct As Long With ThisWorkbook.Worksheets(SHEET) row = ROW_DATA_START ct = 0 Do While .Range("A" & row).Value <> vbNullString ' Condition to delete rows If .Range("H" & row).Value = 0 And _ .Range("I" & row).Value = 0 And _ .Range("J" & row).Value = 0 Then ' Delete row .Rows(row).Delete ' Counter, not necessary ct = ct + 1 ' Account for deleted row row = row - 1 End If ' Next row row = row + 1 Loop End With MsgBox "Finished! Deleted " & CStr(ct) & " row(s)." End Sub

Kevin Chang at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.