deleting rows based on text in a cell

bill151515

Board Regular
Joined
May 19, 2005
Messages
87
is it possible to have a macro select all rows in a worksheet that have the text "delete row" in the cells of column s??? and then delete all those rows

could be rows 1,21,22,55,88 one day and then rows 5,11,99 another
 
Here's a macro you can assign to a custom macro button on your toolbar. Select the cell that contains the text you want deleted and then run this macro:

Code:
Option Explicit

Sub DeleteIfSame()
Dim x As String

'   Abort if a range isn't selected
    If TypeName(Selection) <> "Range" Then
        MsgBox "Please select a single cell", vbOKOnly + vbInformation, "Invalid Range Selection"
        Exit Sub
    End If
    
    If Selection.Cells.count > 1 Then
        MsgBox "Please select a single cell", vbOKOnly + vbInformation, "Invalid Range Selection"""
        Exit Sub
    End If
    
    On Error GoTo endmacro
    x = ActiveCell.Value
    If x = "Error 2042" Then x = ActiveCell.Formula
    
   
    If x = Empty Then
        intResponse = MsgBox("The current cell is empty. Do you wish to delete all rows with an empty cell in the current column?", vbOKCancel, "Delete Rows If Same")
        If intResponse = vbCancel Then
            Exit Sub
        End If
    End If
    intResponse = MsgBox("This macro will delete all rows with " & x & " in the current column", vbOKCancel, "Delete Rows If Same")
    If intResponse = vbOK Then
        With Application
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
'            ActiveCell.EntireColumn.Select
            With ActiveCell.EntireColumn
                .AutoFilter Field:=1, Criteria1:=x
                Rows("2:65536").SpecialCells(xlCellTypeVisible).EntireRow.Delete
                .AutoFilter
            End With
            .Calculation = xlCalculationAutomatic
            .ScreenUpdating = True
        End With
    End If
    
endmacro:
    Application.Calculation = xlCalculationAutomatic
 End Sub

I can't seem to load this macro into 1 thing? can I see the full slot? including the name of the macro?
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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