我想查找範圍內的值,然後刪除該值。如何在單元中查找值並刪除它?
我發現了一些代碼,它尋找的值,但然後刪除其他單元格,而不是找到的值。
這是代碼:
Private Sub CLEAROLD_Click()
'PURPOSE: Clear out all cells that do not contain a specific word/phrase
Dim Rng As Range
Dim cell As Range
Dim ContainWord As String
'What range do you want to search?
Set Rng = Range("AA2:AC25")
'sub for the word
shorttext = traintype1.Value & number1.Value
'What phrase do you want to test for?
ContainWord = shorttext
'Loop through each cell in range and test cell contents
For Each cell In Rng.Cells
If cell.Find(ContainWord) Is Nothing Then cell.ClearContents
Next cell
End Sub
我試圖改變if
條件,但我不能讓它工作。
你做什麼樣的變化? (沒有起作用的更改) – jsotola
在問題標題中沒有必要只使用大寫字母。 – trincot