Delete entire row contains SUM words for each sheet contains 8000 rows

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
174
Office Version
  1. 2019
Platform
  1. Windows
Hi
I search for macro to deal with big data(more than 8000 rows for each sheet) increasing With the passage of time. should search for SUM words in column A for each sheet ,then just delete multiple entires rows contain SUM words at once for each sheet .
there are some sheets doesn't contain SUM words so should ignore it.
thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try:
VBA Code:
Sub DeleteRows()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    On Error Resume Next
    For Each ws In Sheets
        With ws
            .Columns("A").Replace "SUM", "#N/A", xlWhole, , False
            .Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
        End With
    Next ws
    On Error GoTo 0
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi,
works, but is really slow.
could you re-produce it to make fast,please?
 
Upvote 0
See if this speeds it up at all:
VBA Code:
Sub DeleteRows()

    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    Dim ws As Worksheet
    On Error Resume Next
    For Each ws In Sheets
        With ws
            .Columns("A").Replace "SUM", "#N/A", xlWhole, , False
            .Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
        End With
    Next ws
    On Error GoTo 0
    
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    
End Sub
 
Upvote 0
Thanks Joe.
it's too much slow than Mumps' code!
 
Upvote 0
It should definitely NOT be any slower than mumps code, as it is just mumps code with a few commands in there that would only speed up the code, never slow it done (as it suppresses event code from running and calculations while the code is running). This are things people usually do to speed up their code.

If your code is slower, I suspect you have something else interfering with it.
 
Upvote 0
If your code is slower, I suspect you have something else interfering with it.
not sure what you mean , but I made sure there is no others codes!
 
Upvote 0
See if this is faster,
Code:
Sub test()
    Dim ws As Worksheet, x
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    For Each ws In Worksheets
        ws.Columns(1).Insert
        With ws.Range("b1", ws.Range("b" & Rows.Count).End(xlUp)).Columns(0)
            .Formula = "=if(isnumber(search(""sum"",b1)),""z"","""")&row()"
            .Value = .Value
            .EntireRow.Sort .Cells(1), 1
            x = Application.Match("z*", .Cells, 0)
            If IsNumeric(x) Then ws.Rows(x & ":" & .Rows.Count).Delete
        End With
        ws.Columns(1).Delete
    Next
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
thanks Fuji.:)
this is really better .(y)
may you guide me how autonumbering in column A like 1,2,..... after Deletion,please?
 
Upvote 0
Code:
Sub test()
    Dim ws As Worksheet, x
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    For Each ws In Worksheets
        ws.Columns(1).Insert
        With ws.Range("b1", ws.Range("b" & Rows.Count).End(xlUp)).Columns(0)
            .Formula = "=if(isnumber(search(""sum"",b1)),""z"","""")&row()"
            .Value = .Value
            .EntireRow.Sort .Cells(1), 1
            x = Application.Match("z*", .Cells, 0)
            If IsNumeric(x) Then ws.Rows(x & ":" & .Rows.Count).Clear
        End With
        ws.Columns(1).Delete
        With ws.[a1].CurrentRegion
            .Offset(1).Resize(.Rows.Count - 1).Columns(1) = Evaluate("row(1:" & .Rows.Count & ")")
        End With
    Next
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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