0
我试图修改下面的宏(在互联网上的其他地方使用),以便它适用于Excel文件中的所有工作表。但它没有按预期工作。我如何使它工作。删除所有表中包含特定单词的所有列
Sub Col_Delete_by_Word_2()
Dim Found As Range, strWord As String, Counter As Long
Dim CurrentSheet As Object
Dim ws As Worksheet
strWord = Application.InputBox("Enter the word to search for.", _
"Delete the columns with this word", Type:=2)
If strWord = "False" Or strWord = "" Then Exit Sub 'User canceled
Set Found = Cells.Find(strWord, , , xlPart, , xlNext, False)
For Each ws In ActiveWorkbook.Worksheets
If Not Found Is Nothing Then
Application.ScreenUpdating = False
Do
Found.EntireColumn.Delete
Counter = Counter + 1
Set Found = Cells.Find(strWord, , , xlPart, , xlNext, False)
Loop Until Found Is Nothing
Application.ScreenUpdating = True
MsgBox Counter & " columns deleted.", vbInformation, "Process Complete"
Else
MsgBox "No match found for: " & strWord, vbInformation, "No Match"
End If
Next
End Sub
这个单词可以在工作表中的任何地方或只是row1? –
它可以在任何地方 – user3045580
问题是,它无法循环到其他工作表在Excel中,最初没有说清楚,我的英语不是很好:( – user3045580