VBA Delete Row If Cell Contains Value Works For First Sheet But Won't Loop

Worker8ee

New Member
Joined
Aug 8, 2018
Messages
28
The following VBA works for the first sheet that it begins on but won't carry out the same task in the following sheets even though I thought I had coded it correctly to do so, I am not gettin any error message but it just isn't looping, here is what I am using:

Dim sht As Worksheet
For Each sht In ThisWorkbook.Worksheets
With sht
.AutoFilterMode = False
With sht.Range("D5", Range("D" & Rows.Count).End(xlUp))
.AutoFilter 1, "AUGUST"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
Next sht
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try
Code:
Dim sht As Worksheet
For Each sht In ThisWorkbook.Worksheets
   With sht
      .AutoFilterMode = False
      With .Range("D5", .Range("D" & Rows.Count).End(xlUp))
         .AutoFilter 1, "AUGUST"
         On Error Resume Next
         .Offset(1).SpecialCells(12).EntireRow.delete
         On Error GoTo 0
      End With
      .AutoFilterMode = False
   End With
Next sht
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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