title: Deleting Sheet with VBA crashes Excel
body: <p>I am trying to delete a worksheet when the user click's on an image (button) in Excel. However this makes excel crash and restart, forgetting any unsaved progress.</p>
  
  <p>This is my sub:</p>
  
  <pre><code>Sub DeletePlan()
  
  Application.Calculation = xlCalculationManual
  Application.DisplayAlerts = False
  Dim SheetNamesToCopy As String
  
  SheetNamesToCopy = ActiveSheet.Name
  
  
  
  ' Check what addon sheets exists for the media, then add existing ones to string
  If CheckSheet("periodeplan", True) = True Then
      ThisWorkbook.SheetS(SheetNamesToCopy &amp; " - periodeplan").Delete
  End If
  
  If CheckSheet("ukesplan", True) = True Then
      ThisWorkbook.SheetS(SheetNamesToCopy &amp; " - ukesplan").Delete
  End If
  
  If CheckSheet("Input", True) = True Then
      ThisWorkbook.SheetS(SheetNamesToCopy &amp; " - Input").Delete
  End If
  
  SheetS("Totalplan").Select
  ThisWorkbook.SheetS(SheetNamesToCopy).Delete
  
  Application.DisplayAlerts = True
  Application.Calculation = xlCalculationAutomatic
  
  End Sub
  </code></pre>
  
  <p>The application crashes most of the time. But not always... Any ideas what might be wrong?
  (I have tested and confirmed that the delete function causes the crash, but its not always the same sheet).</p>
  
  <p><strong>Edit:</strong> This function is not deleting the last sheet in the workbook. There are 20 more sheets. Also i use <code>Application.Calculation = xlCalculationAutomatic</code>, because there are allot of formulas, and i do not want excel to calculate changes before all is connected sheets are deleted.</p>
  
  <p>Any hint or answer is appreciated :)</p>