我希望将Like
与Case
合并到VBA代码中。我当前的代码能够删除名称与范围A:
Dim MyCell As Range, MyRange As Range
Dim wbook As Workbook, xWs As Worksheet
Dim DeleteSheetFlag As Boolean
Set MyRange = Sheets("Summary").Range("A2")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wbook = ActiveWorkbook
For Each xWs In wbook.Worksheets
DeleteSheetFlag = True
For Each MyCell In MyRange
Select Case xWs.Name
Case MyCell.Value, "Summary"
DeleteSheetFlag = False
Exit For
End Select
Next MyCell
If DeleteSheetFlag Then
xWs.Delete
End If
Next xWs
Application.DisplayAlerts = True
Application.ScreenUpdating = True
我想以这种方式更改它,它会将名称不是类似的所有工作表移除到范围A中的名称。如果我能够获得类似
的内容 Case **Like** MyCell.Value, "Summary"
DeleteSheetFlag = False
问题将得到解决。 我的意思是类似于我们从Regular Expressions知道的模式匹配。在我的情况下,我有两张名为: Etat1 和 Etat1(2)的表格,我想在中输入字符串 Eta 为了保持两者。
答案 0 :(得分:2)
要强制执行此操作,您需要使用以下解决方法:
Select Case True
Case MyCell.Value Like "*Summary*"
Debug.Print "!"
'DeleteSheetFlag = False
'...
Case MyCell.Value Like "*OtherCase*"
DeleteSheetFlag = False
'...
End Select