Exception to a rule within a Macro

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I have the macro below which works perfectly in removing rows if a column contains specific text. I would like to add an exception to the rule. If I have "B737", "A310", "B767" , or "B777" in Column C I would like those rows NOT to be removed if otherwise would be removed based on the macro: Thank you,


VBA Code:
Sub Delete_locals()
With ActiveSheet
.AutoFilterMode = False
With Range("H1", Range("H" & Rows.Count).End(xlUp))
.AutoFilter 1, "*CHS*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
With ActiveSheet
.AutoFilterMode = False
With Range("H1", Range("H" & Rows.Count).End(xlUp))
.AutoFilter 1, "*777*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub
 
No answer to my question about macro buttons?

You now continue to talk about aircraft. I have no idea what that relates to or what column that is in. Assume your helpers know nothing about your data and layout. Make it clear for them. As 6StringJazzer has alluded to several times already in the thread, some sample data (& expected results) would be very helpful! XL2BB

Yet another new concept has now been introduced: Hidden values in column C. Again we know nothing about that that.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
VBA Code:
Sub Delete_locals()
    Dim rngExclude As Range
   
    With ActiveSheet
        .AutoFilterMode = False
        With Range("C1", Range("C" & Rows.Count).End(xlUp))
            .AutoFilter 1, Array("B737", "A310", "B767", "B777"), Operator:=xlFilterValues
            On Error Resume Next
            Set rngExclude = .Offset(1).SpecialCells(12).EntireRow
        End With
        .AutoFilterMode = False
       
        With Range("H1", Range("H" & Rows.Count).End(xlUp))
            .AutoFilter 1, Array("*CHS*", "*777*"), Operator:=xlFilterValues
            On Error Resume Next
            rngExclude.Hidden = True
            .Offset(1).SpecialCells(12).EntireRow.Delete
        End With
        .AutoFilterMode = False
    End With
   
End Sub
Thank you I went with your response in the end. I had to create another macro just to clean Column C up. Below is the macro I am referring to. Thank you and have a nice weekend.
VBA Code:
Sub remove_hidden_Values_ColumnnC()
With ActiveSheet
For Each Cell In Range("C1", Range("C" & Rows.Count).End(xlUp))
        Cell.Value = Trim(Replace(Cell.Value, Chr(160), Chr(32)))
    Next
    End With
End Sub
 
Upvote 0
Thank you everyone for your help. I know I can be trying, but I am doing my best. After about 8 to 10 more hours working on it, I finally got 'Alpha Frog's" suggestion to work, and it works great? I just had to add another macro before it. I got my data from a website, and some Columns end up having hidden values in. The macro I used was.
VBA Code:
Sub remove_hidden_Values_ColumnnC()
With ActiveSheet
For Each Cell In Range("C1", Range("C" & Rows.Count).End(xlUp))
        Cell.Value = Trim(Replace(Cell.Value, Chr(160), Chr(32)))
    Next
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,569
Messages
6,120,286
Members
448,953
Latest member
Dutchie_1

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