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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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