Test or check if sheet exists

后端 未结 22 2545
深忆病人
深忆病人 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条回答
  •  被撕碎了的回忆
    2020-11-22 00:19

    Change "Data" to whatever sheet name you're testing for...

    On Error Resume Next 
    
    Set DataSheet = Sheets("Data")
    
    If DataSheet Is Nothing Then
    
         Sheets.Add(after:=ActiveSheet).Name = "Data"
         ''or whatever alternate code you want to execute''
    End If
    
    On Error GoTo 0
    

提交回复
热议问题