這樣你就可以去了該數組裏面與要檢查裏面的數據值/字符串:
Sub DeleteRows()
Dim c As Range
Dim i
Dim r
Dim theValues(1 To 5)
Dim SrchRng As Range
theValues(1) = "1231"
theValues(2) = "1232"
theValues(3) = "1233"
theValues(4) = "1234"
theValues(5) = "1235"
r = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set SrchRng = Range(Cells(1, 1), Cells(r, 1))
For Each i In theValues
Do
Set c = SrchRng.Find(i, LookIn:=xlValues, LookAt:=xlWhole)
'see the ", LookAt:=xlWhole" added, this way you can find just the Whole values.
If Not c Is Nothing Then c.EntireRow.Delete
Loop While Not c Is Nothing
Next i
End Sub
編輯#1 當您在留言問,請參閱編輯以便:查看僅顯示完整值的數據(您可以查找91
而不是910
或1891
),然後繼承人是我的版本,如果要將值放入工作表中的某個範圍內,則可以添加任何值被發現。
Sub DeleteRows()
Dim c As Range
Dim i
Dim r
Dim rng As Range
Dim a
Dim theValues()
Dim SrchRng As Range
r = Range("T1").End(xlDown).Row
Set rng = Range("T1", Cells(r, 20))
For a = 1 To rng.Count 'in this range i store the values
ReDim Preserve theValues(1 To a)
theValues(a) = rng(a)
Next a
r = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set SrchRng = Range(Cells(1, 1), Cells(r, 1))
For Each i In theValues
Do
Set c = SrchRng.Find(i, LookIn:=xlFormulas, LookAt:=xlWhole)
If Not c Is Nothing Then c.EntireRow.Delete
Loop While Not c Is Nothing
Next i
End Sub
檢查我的anser並編輯。 –