?
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
Medium Priority
?
64 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 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 34

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
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‚Ķ

752 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