title: VBA Code Does Not Copy Worksheet For the Second Time If I Add A Button To The Copied Sheet
body: <p>I have a VBA code that copies the chosen page in the workbook, manipulates it in a desired way and creates a report on a new worksheet. The next thing I want to do is to add a close button to the newly created report sheet. However, when I do this and close the report sheet using the button, the next time I try to get the same report, it gives a subscript out of range error. Here is the code for copying the worksheet: </p>
  
  <pre><code>Sheets(UserForm1.ComboBox3.Value).Copy After:=Sheets("Sheet1")
  Sheets(Sheets.Count).Name = UserForm1.ComboBox3.Value &amp; UserForm1.ComboBox1.Value
  </code></pre>
  
  <p>And here is the code that adds the button:</p>
  
  <pre><code>    Set btn = Sheets(Sheets.Count).Buttons.Add(3, 3.75, 93, 16.5)
      btn.OnAction = "raporKapat"
      btn.Characters.Text = "Kapat"
  </code></pre>
  
  <p>And here is the "raporKapat" macro that it refers to:</p>
  
  <pre><code>Private Sub raporKapat()
  Application.DisplayAlerts = False
  
  ActiveSheet.Delete
  
  Application.DisplayAlerts = True
  End Sub
  </code></pre>
  
  <p>Any help is greatly appreciated.
  P.S. the program works flawlessly without the close button.</p>