Delete Rows not needed Macro

zone709

Well-known Member
Joined
Mar 1, 2016
Messages
2,129
Office Version
  1. 365
Platform
  1. Windows
I need to delete 2 kind of rows Macro. If H or I have a 0 or 0.00 in it. Then delete that row but i also need to delete one row above it also.
On Sheet2 i have Example the clean look and i am realizing if i can delete Column H or I with a 0 or 0.00 in them. Then also delete the row above it. Only Above not below.
You can see the rows with zeros i don't need. Then mostly not all have the same name above row. Deleting both i think would clean my whole sheet. (above only)

Test Macro Work.xlsx
ABCDEFGHI
1AMD
2Bill7/1/2024110Fine Street7/31/20247,500.007,500.00
3Total AMD7,500.007,500.00
4American
5Beac00
6American General
7Bill8/14/202434394Fine Street9/13/20245,197.915,197.91
8Total American General5,197.915,197.91
9Landscaping LLC
10Landscaping LLC00
11Corporation
12Corporation00
13Fuel Corpration
14Fuel Corpration00
15Arrow
16Bill7/1/202421049Fine Street7/31/202410,450.0010,450.00
17Bill8/1/202421170Fine Street8/31/202410,450.0010,450.00
Sheet1


Example Results

Test Macro Work.xlsx
ABCDEFGHI
1AMD
2Bill7/1/2024110Fine Street7/31/20247,500.007,500.00
3Total AMD7,500.007,500.00
4American General
5Bill8/14/202434394Fine Street9/13/20245,197.915,197.91
6Total American General5,197.915,197.91
7Arrow
8Bill7/1/202421049Fine Street7/31/202410,450.0010,450.00
9Bill8/1/202421170Fine Street8/31/202410,450.0010,450.00
Sheet2
 
Hi leave them alone. I run a macro first before i then run this macro. I do not clean it up till after. So when i run the above first ill have ref in those cells at start. Wanted to work around it so the above macro can run anyway with the Ref in place.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this change then:

VBA Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    For r = lr To 2 Step -1
      if not iserror(Cells(r, "H").Value) then
        If (Cells(r, "H").Value = 0 Or Cells(r, "I").Value = 0) And _
            (Cells(r, "H").Value <> "" Or Cells(r, "I").Value <> "") Then
            Range(Cells(r, "H"), Cells(r - 1, "H")).EntireRow.Delete
         End If
      end if
    Next r
End Sub
 
Upvote 0
This works great and works around the #ref. Thank you and to everyone thank you again. (y)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top