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) –