Excel vba 模糊查找工作表名,并选中工作表

Sub SelSht() '工作表查找
Dim Sht As String
Dim str As String
On Error Resume Next
Sht = Application.InputBox(prompt:="请输入要查找的值:", Title:="模糊查找", Type:=2)
Sheets(Sht).Select
str = Err.Description
If str <> "" Then
MsgBox "不存在或名称输入有误!"
End If
End Sub

上面这个要怎么改成模糊查找工作表名称?

Sub SelSht() '工作表查找
    Dim Sht As String
    Dim str As String
    Dim st as WorkSheet
    Sht = Application.InputBox(prompt:="请输入要查找的值:", Title:="模糊查找", Type:=2)
    str=""
    for each st in sheets
        if st.name like "*"& sht &"*" then
            st.activate
            st.select
            str="ok"
            exit for
        end if
    nest st
     If str <> "ok" Then
     MsgBox "不存在或名称输入有误!"
     End If
End Sub
温馨提示:答案为网友推荐,仅供参考
相似回答