我有以下代碼搜索 D 列中的每個單元格并洗掉包含字串“Text1”的每一行。我現在需要擴展洗掉條件以查找字串“Text 2”,但在 C 列中。我可以用這段代碼做什么,所以它只洗掉 D 列中帶有字串“Text1”和“Text2”的行C 列?
Dim Cell As Range, cRange As Range, LastRow As Long, x As Long
' Defines LastRow as the last row of data based on column D
LastRow = Sheets(Sheet1).Cells(Rows.Count, "D").End(xlUp).Row
' Sets check range as D2 to the last row of D
Set cRange = Range("D2:D" & LastRow)
' For each cell in the check range, working from the bottom upwards
For x = cRange.Cells.Count To 1 Step -1
With cRange.Cells(x)
' If the cell contains "Text1", delete entire row
If InStr(.Value, "Text1") > 0 Then
.EntireRow.Delete
End If
End With
' Check next cell, working upwards
Next x
uj5u.com熱心網友回復:
相當粗糙,但改變這個
If InStr(.Value, "Text1") > 0 Then
對此
If InStr(.Value, "Text1") > 0 And InStr(.Offset(0, -1).Value, "Text 2") > 0 Then
未經測驗,因為我在我的手機上,但試試看。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/518029.html
標籤:擅长vba
上一篇:如何在MicrosoftWord檔案中快速搜索Google上的選定文本?
下一篇:如果單元格不包含命名串列中的值
