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