1
我搜索已經和我沒有運氣找到正確的答案或創建我的代碼:如何在刪除整行時添加多個條件?
此代碼將刪除包含在山口D.「蘋果」整行
我將如何添加條件在strSearch?我想添加「香蕉」和「貓」?
Sub Delete_EntireRow_Values()
'
' Delete_EntireRow_Values Macro
Dim rFind As Range
Dim rDelete As Range
Dim strSearch As String
Dim sFirstAddress As String
strSearch = "apple"
Set rDelete = Nothing
Application.ScreenUpdating = False
With Sheet1.Columns("D:D")
Set rFind = .Find(strSearch, LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlNext, MatchCase:=False)
If Not rFind Is Nothing Then
sFirstAddress = rFind.Address
Do
If rDelete Is Nothing Then
Set rDelete = rFind
Else
Set rDelete = Application.Union(rDelete, rFind)
End If
Set rFind = .FindNext(rFind)
Loop While Not rFind Is Nothing And rFind.Address <> sFirstAddress
rDelete.EntireRow.Delete
End If
End With
Application.ScreenUpdating = True
End Sub