Delete rows if column A has a specific data value with VBA

Dokat

Active Member
Joined
Jan 19, 2015
Messages
304
Office Version
  1. 365
Hi,

I have a large spreadsheet with value from column a through F.I would like to write a code where if column A has a value 4/1/2022 or 4/30/22 VBA code to delete entire row.. There are over 200K rows and the number increases every month


I tried below code however keep receiving error message. I would appreciate if anyone can help me with the below code.


Sub Delete_Rows_Based_On_Value()
Dim ws As Worksheet

Set ws = ThisWorkbook.Worksheets("P&L (2)")
ws.Activate

On Error Resume Next
ws.ShowAllData
On Error GoTo 0

ws.Range("A").AutoFilter Field:=1, Criteria1:="4/1/2022, 4/30/2022"

Application.DisplayAlerts = False
ws.Range("A:F").SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True

On Error Resume Next
ws.ShowAllData
On Error GoTo 0

End Sub
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
This adjustment seems to work for me:
VBA Code:
Sub Delete_Rows_Based_On_Value()
Dim ws As Worksheet

Set ws = ThisWorkbook.Worksheets("P&L (2)")
ws.Activate

On Error Resume Next
ws.ShowAllData
On Error GoTo 0

ws.Range("A:F").AutoFilter Field:=1, Operator:= _
        xlFilterValues, Criteria2:=Array(2, "4/1/2022", 2, "4/30/2022")

Application.DisplayAlerts = False
ws.Range("A:F").SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True

On Error Resume Next
ws.ShowAllData
On Error GoTo 0

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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