delete rows contains TOTAL word across sheets

Mussala

Board Regular
Joined
Sep 28, 2022
Messages
63
Office Version
  1. 2019
Platform
  1. Windows
Hi
I have rows some of them contains TOTAL word in column A for just two sheets(sh, mn) . I want deleting the whole rows contain TOTAL word in column A for two sheets.
thanks
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try the following - tested on 2 sheets of 25K rows around 0.25 seconds.
VBA Code:
Option Explicit
Sub Mussala_V2()
    Application.Calculation = xlManual
    Application.ScreenUpdating = False
    Dim ws As Worksheet, LRow As Long, LCol As Long, i As Long, a, b
    
    For Each ws In ThisWorkbook.Worksheets
        Select Case ws.Name
            Case "sh", "mn"
            LRow = ws.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
            LCol = ws.Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column + 1
            a = Range(ws.Cells(2, 1), ws.Cells(LRow, 1))
            ReDim b(1 To UBound(a), 1 To 1)
            For i = 1 To UBound(a)
                If a(i, 1) = "TOTAL" Then b(i, 1) = 1
            Next i
            ws.Cells(2, LCol).Resize(UBound(a)) = b
            i = WorksheetFunction.Sum(ws.Columns(LCol))
            If i > 0 Then
                ws.Range(ws.Cells(2, 1), ws.Cells(LRow, LCol)).Sort Key1:=ws.Cells(2, LCol), _
                order1:=xlAscending, Header:=xlNo
                ws.Cells(2, LCol).Resize(i).EntireRow.Delete
            End If
        End Select
    Next ws
    Application.Calculation = xlAutomatic
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Filter column A for the condition "Contains ... Total"; then select the displayed rows and Delete them.
 
Upvote 0
You might record a macro:
-start from Sheet2
-start recording the macro
-select sheet1, apply filter to column A, filter for "Contains ... Total"
-select fromthe visible rows and delete them
-remove the filter
-move to sheet2 and repeat
-stop recording when job done
Examine the recorded code; it migh be wise to extend the rows selected (ready to be deleted) up to (say) line 10,000 (or a value surely above your lines)

Try...
 
Upvote 0
ok i will try it, and comeback when I need help , despite of I don't use before .
 
Upvote 0
ok i will try it, and comeback when I need help , despite of I don't use before
Recording a macro is a great feature, and returns code properly working in most of the cases.
If you post the code that you get we can review it and maybe suggest some improvements
 
Upvote 0
when I do this step
-select sheet1, apply filter to column A, filter for "Contains ... Total"
then will hide the others rows . so how do I this is step
-select fromthe visible rows and delete them
if the others rows are hidden ?!
 
Upvote 0
After the filter, only rows with Total are visible; if you select all the visible rows (except the header) and delete them then you you should get what you look far: "delete rows contains TOTAL word" (hidden rows cannot be selected and thus will not be deleted)
 
Upvote 0
here is what I got
VBA Code:
Sub Macro1()
'
' Macro1 
'

'
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$A$1969").AutoFilter Field:=1, Criteria1:= _
        "TOTAL"
    Rows("3:52").Select
    Selection.Delete Shift:=xlUp
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,884
Messages
6,127,561
Members
449,385
Latest member
KMGLarson

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