Help modifying VBA code

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
I'm using the code below which works great provided the word "Remove" is somewhere on the sheet in column F. However, when the code runs on a worksheet where the word "Remove" is not present it removes the first row of the worksheet which is the column headings and also removes my alternate row colors. I'd like to modify this code or, new code that will eliminate this issue.

'Delete rows for Leases worksheet that contain the word "Remove" - column F
Worksheets("Leases").Activate
With ActiveSheet
.AutoFilterMode = False
With Range("F1", Range("F" & Rows.Count).End(xlUp))
.AutoFilter 1, "*Remove*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With

Thanks for any help.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
How about
Code:
Worksheets("Leases").Activate
With ActiveSheet
   .AutoFilterMode = False
   If Application.CountIf(.Range("F:F"), "*Remove*") > 0 Then
      With Range("F1", Range("F" & Rows.Count).End(xlUp))
         .AutoFilter 1, "*Remove*"
         .Offset(1).SpecialCells(12).EntireRow.Delete
      End With
   End If
   .AutoFilterMode = False
End With
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,978
Members
448,934
Latest member
audette89

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