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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,224,743
Messages
6,180,687
Members
452,994
Latest member
Janick

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