Test or check if sheet exists

后端 未结 22 2845
深忆病人
深忆病人 2020-11-21 23:51
Dim wkbkdestination As Workbook
Dim destsheet As Worksheet

For Each ThisWorkSheet In wkbkorigin.Worksheets 
    \'this throws subscript out of range if there is not         


        
22条回答
  •  萌比男神i
    2020-11-22 00:13

    Without any doubt that the above function can work, I just ended up with the following code which works pretty well:

    Sub Sheet_exist ()
    On Error Resume Next
    If Sheets("" & Range("Sheet_Name") & "") Is Nothing Then
        MsgBox "doesnt exist"
    Else
        MsgBox "exist"
    End if
    End sub
    

    Note: Sheets_Name is where I ask the user to input the name, so this might not be the same for you.

提交回复
热议问题