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
Related Q & A:
- How can I plot more than one value in the same date?Best solution by Mathematica
- How can i delete the links that posted on my status?it bothers my im to frends.pls help me delete that?Best solution by Yahoo! Answers
- How do I delete new status messages that I have created?Best solution by Yahoo! Answers
- I have the new iPod nano how do i delete the songs from the ipod.Best solution by Yahoo! Answers
- How can I start web based Yahoo Messenger (without downloading)?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.