If Cell Equals "" Delete Row Macro

shawn2209

New Member
Joined
Jul 15, 2017
Messages
18
I am needing a macro formula for if a cell = "DELETE ME" then it will delete that row.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
What Column would "Delete Me" be in and do you want this to look at all rows on a single worksheet or all worksheets in a workbook?
 
Upvote 0
Hi there,

Here's one way for smaller datasets (run it while on the "Overage Tracking Running Report" sheet):

Code:
Option Explicit
'Option Compare Text 'Ignores case sensitivity
Sub Macro2()

    Dim lngMyRow As Long
    
    Application.ScreenUpdating = False
    
    For lngMyRow = Cells(Rows.Count, "L").End(xlUp).Row To 2 Step -1 'Works backwards up Col. L to Row 2. Change to suit if necessary.
        If Range("L" & lngMyRow) = "DELETE ME" Then 'Case sensitive.  If you don't want case sensitivity, comment out the line of code immediately under Option Explicit
            Rows(lngMyRow).EntireRow.Delete
        End If
    Next lngMyRow
    
    Application.ScreenUpdating = True

End Sub

Just make sure to initially run it on a copy of your data as the results cannot be undone if they're not as expected.

Regards,

Robert
 
Last edited:
Upvote 0
So I have the formula that says "DELETE ME" in worksheet "Overage Tracking Running Report" will it go recognize that sheet or will it go through the whole workbook to find "DELETE ME" and clear that row?
 
Upvote 0
Ok and sorry, I just though of this. If I delete the whole row then it will erase the formula in L for future additions to that sheet. Can I get a macro that clear contents just from A:F on that row?
 
Upvote 0
Ok and sorry, I just though of this. If I delete the whole row then it will erase the formula in L for future additions to that sheet. Can I get a macro that clear contents just from A:F on that row?

Try this while you're on the "Overage Tracking Running Report" tab:

Code:
Option Explicit
'Option Compare Text 'Ignores case sensitivity
Sub Macro2()

    Dim lngMyRow As Long
    
    Application.ScreenUpdating = False
    
    For lngMyRow = Cells(Rows.Count, "L").End(xlUp).Row To 2 Step -1 'Worksbackwards up Col. L to Row 2. Change to suit if necessary.
        If Range("L" & lngMyRow) = "DELETE ME" Then 'Case sensitive.  If you don't want case sensitivity, comment out the line of code immediately under Option Explicit
            Range("A" & lngMyRow & ":F" & lngMyRow).ClearContents
        End If
    Next lngMyRow
    
    Application.ScreenUpdating = True

End Sub

Robert
 
Last edited:
Upvote 0
I am wanting to assign this macro to a button on another sheet. Will this still work?

No. This should (you'll need to test it on a copy of the workbook):

Code:
Option Explicit
'Option Compare Text 'Ignores case sensitivity
Sub Macro2()

    Dim wsMyTab  As Worksheet
    Dim lngMyRow As Long
    
    Application.ScreenUpdating = False
    
    Set wsMyTab = Sheets("Overage Tracking Running Report")
    
    For lngMyRow = wsMyTab.Cells(Rows.Count, "L").End(xlUp).Row To 2 Step -1 'Worksbackwards up Col. L to Row 2. Change to suit if necessary.
        If wsMyTab.Range("L" & lngMyRow) = "DELETE ME" Then 'Case sensitive.  If you don't want case sensitivity, comment out the line of code immediately under Option Explicit
            wsMyTab.Range("A" & lngMyRow & ":F" & lngMyRow).ClearContents
        End If
    Next lngMyRow
    
    Set wsMyTab = Nothing
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
I apologize if I am asking questions that seems like I should already know. I am new to the macro game and I will accept any advice if I am asking the wrong questions. Let me see if more information would help you help me. I am working between two tabs or maybe the excel term is work sheet within the work book. On " Overage Tracking Running Report" in L column I have formula =IF(AND(B1='Look up'!A13,D1='Look up'!C13,E1='Look up'!D13,F1='Look up'!E13),"DELETE ME",""). On the tab "Look up" I want to push a button to when the information is there for "DELETE ME" to show up in column L then it would clear contents in A:F. If there is more information you are needing the please let me know. I really do appreciate the help that you are giving me right now to complete this.
 
Upvote 0

Forum statistics

Threads
1,223,997
Messages
6,175,874
Members
452,679
Latest member
darryl47nopra

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