Solved

How can I modify this Excel macro to delete a row if the A field is blank, and the B field is 0?

Posted on 2015-02-19
2
59 Views
Last Modified: 2015-02-25
I want to modify this macro so that if the A field is blank, and the corresponding B field has '0' in it, or '0.00', then delete the entire row.


  Sub Step2_DeleteBlankRows()

            'Deletes the entire row within the selection if the ENTIRE row contains no data.

            'We use Long in case they have over 32,767 rows selected.

            Dim i As Long

                'We turn off calculation and screenupdating to speed up the macro.

                With Application

                    .Calculation = xlCalculationManual

                    .ScreenUpdating = False

                'We work backwards because we are deleting rows.

                For i = Selection.Rows.Count To 1 Step -1

                    If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then

                        Selection.Rows(i).EntireRow.Delete

                    End If

                Next i

                    .Calculation = xlCalculationAutomatic

                    .ScreenUpdating = True

                End With

            End Sub
0
Comment
Question by:100questions
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40619753
Try changing

If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then

to

If Selection.cells(i,1)="" and (Selection.cells(i,2)=0 or Selection.cells(i,2)="0.00") Then
0
 
LVL 33

Expert Comment

by:Norie
ID: 40619766
Perhaps.
                For i = Selection.Rows.Count To 1 Step -1

                    If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Or (Selection.Cells(i, 1)="" And Selection.Cells(i, 2)=0) Then

                        Selection.Rows(i).EntireRow.Delete

                    End If

                Next i

Open in new window

0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vlookup for in-between dates 4 38
Excel VBA - triggering a Sheet event on another workbook 3 29
Excel VBA 4 26
Excel Drop Down List 13 31
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question