VBA:保持行如果特定的值存在

我正在处理我的第一个VBA脚本,并从这里find的示例工作:http://www.rondebruin.nl/win/s4/win001.htm

这似乎很适合删除符合条件“ron”,“Dave”,“Jelle”的行,但是我想使代码成为KEEPS行,例如“Ron A”,“ron B”,“C RON “,”戴夫A“,”DAVE B“并删除其余部分。 换句话说,我想让它不是特定的,不是特定的订单,而是保留而不是删除。

input:

  • 罗恩A
  • 乔治h
  • 罗恩B
  • C RON
  • 戴夫A
  • 约翰f
  • JIM R

输出:

  • 罗恩A
  • 罗恩B
  • C RON
  • 戴夫A

先谢谢你。

Sub Delete_with_Autofilter_Array() Dim rng As Range Dim calcmode As Long Dim myArr As Variant Dim I As Long With Application calcmode = .Calculation .Calculation = xlCalculationManual .ScreenUpdating = False End With 'Fill in the values that you want to delete myArr = Array("ron", "Dave", "Jelle") For I = LBound(myArr) To UBound(myArr) 'Sheet with the data, you can also use Sheets("MySheet") With ActiveSheet 'Firstly, remove the AutoFilter .AutoFilterMode = False 'Apply the filter .Range("A1:A" & .Rows.Count).AutoFilter Field:=1, Criteria1:=myArr(I) Set rng = Nothing With .AutoFilter.Range On Error Resume Next Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _ .SpecialCells(xlCellTypeVisible) On Error GoTo 0 If Not rng Is Nothing Then rng.EntireRow.Delete End With 'Remove the AutoFilter .AutoFilterMode = False End With Next I With Application .ScreenUpdating = True .Calculation = calcmode End With End Sub