How to delete multiple rows based on meeting a criteria of matching data?

ordinaryassistant

New Member
Joined
Aug 14, 2018
Messages
2
Based on a spreadsheet monitoring attendance, I'm looking for a more efficient way of deleting rows in the below screenshot based on a row hitting more then 4 zeros in a row.
There is currently 800 rows and it is tedious to go through individual rows to delete as identified by the rows highlighted in red.
If anyone could provide any tips or hints that would be extremely appreciated.

0nwQWLM.png
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi ordinaryassistant,

Welcome to MrExcel!!

Try the following macro while on the tab with the data. Note to first run it on a copy of your data as the results cannot be undone if they're not as expected. Note also that I've assumed the four columns you referred to are D to G (inclusive).

HTH

Robert

Code:
Option Explicit
Sub Macro1()

    Dim lngMyRow   As Long
    Dim lngLastRow As Long
    
    Application.ScreenUpdating = False
    
    lngLastRow = Range("A:G").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    For lngMyRow = lngLastRow To 3 Step -1
        If Evaluate("SUM(D" & lngMyRow & ":G" & lngMyRow & ")") = 0 Then
            Rows(lngMyRow).EntireRow.Delete
        End If
    Next lngMyRow
    
    Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0
Hi ordinaryassistant,

Welcome to MrExcel!!

Try the following macro while on the tab with the data. Note to first run it on a copy of your data as the results cannot be undone if they're not as expected. Note also that I've assumed the four columns you referred to are D to G (inclusive).

HTH

Robert

Code:
Option Explicit
Sub Macro1()

    Dim lngMyRow   As Long
    Dim lngLastRow As Long
    
    Application.ScreenUpdating = False
    
    lngLastRow = Range("A:G").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    For lngMyRow = lngLastRow To 3 Step -1
        If Evaluate("SUM(D" & lngMyRow & ":G" & lngMyRow & ")") = 0 Then
            Rows(lngMyRow).EntireRow.Delete
        End If
    Next lngMyRow
    
    Application.ScreenUpdating = True

End Sub

That's perfect thank you so much!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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