列 A のいずれかのセルに「Total」という単語が含まれている場合、行全体を削除する vba コードを知っている人はいますか? たとえば、A38 に「Total」が含まれている場合は、その行全体を削除します。翌月、セル A44 に「total」という単語が含まれているので、その行全体を削除します。などなど…。ありがとうございます!
1968 次
1 に答える
0
以下でテストを実行し、必要なものに近いかどうかを確認してください。
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
于 2013-10-28T19:38:38.977 に答える