Delete rows based on cell value change

Enzo_Matrix

Board Regular
Joined
Jan 9, 2018
Messages
113
I have a code to delete specific rows depending on whether or not the cell value is set to "Void".
Code:
Sub DeleteRows()    Dim c As Range
    Dim SrchRng


    Set SrchRng = ActiveSheet.Range("E1", ActiveSheet.Range("E65536").End(xlUp))
    Do
        Set c = SrchRng.Find("Void", LookIn:=xlValues)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
End Sub

There is a daily dump that can add anywhere from 10-50 rows to my table and I'm trying to get this to run automatically as the data in my table changes. After some Googling I found this but it does not work run automatically.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)If Target.Address = "$A$2" Then
Dim c As Range
    Dim SrchRng


    Set SrchRng = ActiveSheet.Range("E1", ActiveSheet.Range("E65536").End(xlUp))
    Do
        Set c = SrchRng.Find("Void", LookIn:=xlValues)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
End If
End Sub
 

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).
this assumes data is in every cell in col (A)
and the Void is in col E

Code:
Public Sub ScanRows2Del()
Sheets("sheet1").Activate
Range("A1").Select
FarDown
 'start at bottom
While ActiveCell.row >1 
   If ActiveCell.Offset(0, 4).Value = "Void" Then        'if col 4 (E) = "void" then delete it
      Delete1Row ActiveCell.Row
   End If
   PrevRow
Wend
End Sub


Private Sub PrevRow()
ActiveCell.Offset(-1, 0).Select
End Sub


Private Sub FarDown()
    Selection.End(xlDown).Select
End Sub


Private Sub Delete1Row(ByVal plRow As Long)
    Rows(plRow & ":" & plRow).Select
    Selection.Delete Shift:=xlUp
End Sub
 
Last edited:
Upvote 0
When you say data in every cell in column A..does that mean the entire column A:A is filled?

As it sits right now I only have data in A2:E100. Will that code work as I increase the data range?
 
Upvote 0
this works, but it does not run automatically.
I still have to open the VBA code and run manually. Once I do, it gives me the option of which Macro I want to execute.

After I execute the 'Delete1Row' Macro it removes all the rows with 'Void' in it
 
Upvote 0

Forum statistics

Threads
1,224,749
Messages
6,180,727
Members
452,995
Latest member
isldboy

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