如何在写入部分名称时擦除表格是工作表名称?

时间:2015-04-08 14:15:24

标签: excel-vba vba excel

如何告诉VBA,如果工作表的名称包含名称" name"部分单词" name"要彻底擦掉那张纸吗?

当工作表没问题时,在工作表名称

中写入了一个普通名称

当纸张被称为纸张时,#34;名称1"或"名称2"等等,直到"名称30"

我必须删除blanc表。

在我的尝试之下,但没有工作。

Sub erasesheet(wbNew As Workbook)   
Dim ws As Worksheet

For Each ws In Worksheets

'here I have to be able to tell : I it contains the word "name" in the sheet
'like the code is now it will only look exactly fot sheets with name "name"
      If Sheets.Name = "name"   Then
         Application.DisplayAlerts = False
         ws.Delete
      Application.DisplayAlerts = True
     End If
  Next ws
end sub

1 个答案:

答案 0 :(得分:2)

您需要使用Instr。请尝试以下代码

Sub erasesheet(wbnew As Workbook)
    Dim ws As Worksheet

    For Each ws In wbnew.Worksheets
        If InStr(1, UCase(ws.Name), "NAME") Then
            Application.DisplayAlerts = False
            ws.Delete
            Application.DisplayAlerts = True
        End If
      Next ws
End Sub