Help modifying VBA code

kevinh2320

New Member
Joined
May 13, 2016
Messages
32
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,004
Office Version
365
Platform
Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,004
Office Version
365
Platform
Windows
Glad to help & thanks for the feedback
 

Forum statistics

Threads
1,081,574
Messages
5,359,704
Members
400,545
Latest member
Damntheman30

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top