0
如果列A中的單元格包含單詞「總計」,是否有人知道刪除整行的vba代碼?例如,A38包含「Total」,刪除整行。下個月,單元格A44包含單詞「total」,刪除整行。等等....謝謝!如果單元格包含指定的單詞,則刪除行
如果列A中的單元格包含單詞「總計」,是否有人知道刪除整行的vba代碼?例如,A38包含「Total」,刪除整行。下個月,單元格A44包含單詞「total」,刪除整行。等等....謝謝!如果單元格包含指定的單詞,則刪除行
給下面的測試運行,看看它是否接近你想要的。
Sub TestDeleteRows()
Dim rFind As Range
Dim rDelete As Range
Dim strSearch As String
Dim iLookAt As Long
Dim bMatchCase As Boolean
strSearch = "Total"
iLookAt = xlPart 'Change to xlWhole if the entire cell must equal search string
bMatchCase = False 'Change to True if you want search to be case sensitive
Set rDelete = Nothing
Application.ScreenUpdating = False
With Sheet1.Columns("A:A")
Set rFind = .Find(strSearch, LookIn:=xlValues, LookAt:=iLookAt, SearchDirection:=xlPrevious, MatchCase:=bMatchCase)
If Not rFind Is Nothing Then
Do
Set rDelete = rFind
Set rFind = .FindPrevious(rFind)
If rFind.Address = rDelete.Address Then Set rFind = Nothing
rDelete.EntireRow.Delete
Loop While Not rFind Is Nothing
End If
End With
Application.ScreenUpdating = True
End Sub
所以,你要「迴路」通過所有的「細胞在第1行,第1列」並選中「Cells.Value」,看看這個詞總爲「InStr函數」,這將返回的東西大於0然後取出Cells.EntireRow.Delete它。如果你給它一個鏡頭,不應該很難。 – Sorceri
This [鏈接](http://stackoverflow.com/questions/17562694/faster-and-efficient-way-of-deleting-rows/17562870#17562870)可能會有所幫助。 – Santosh
使用[自動填充]的另一種方法(http://stackoverflow.com/questions/11631363/how-to-copy-a-line-in-excel-using-a-specific-word-and-pasting-to-another- Excel中-S) –