Q:

Excel crashes after I run this macro - blank error report

I am running this simple macro. The goal is to create new Data sheet on a click of a userform button (deleting the old one). After making a copy from a raw data sheet, it should rename it "Data". If sheet named "Data" already exists - delete it. 
Private Sub CommandButton1_Click()
Dim ws1 As Worksheet
Dim trigger As Integer

trigger = 0

Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = 1 To Sheets.Count
    If Sheets(i).Name = "Data" Then
        trigger = 1
        Sheets("Data").Delete
        Sheets("raw_Data").Visible = True
    Set ws1 = Sheets("raw_Data")
    ws1.Copy Sheets(Sheets.Count)
    Sheets("raw_Data").Visible = False
    End If
Next i

If trigger = 0 Then
    Sheets("raw_Data").Visible = True
    Set ws1 = ThisWorkbook.Worksheets("raw_Data")
    ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
    Sheets("raw_Data").Visible = False
End If

Application.ScreenUpdating = True
Application.DisplayAlerts = True
Unload Me
    ActiveSheet.Name = "Data"
End Sub

Am I running some kind of infinite loop here? If I delete:
    ActiveSheet.Name = "Data"

Excel isn't crashing any more.

A:

I am with Ron on this one. I made a little bit cleaner version of the code and maybe it will shed some light to what the problem is. 
Option Explicit

Private Sub CommandButton1_Click()

    Const strDATA_SHEET As String = "Data"
    Const strDATA_RAW_SHEET As String = "raw_Data"

    Dim shDataRaw As Worksheet

    Call TurnExtrasOff

    ' Check if we have the sheet data if so then delete it
    If DoesWorksheetExist(strDATA_SHEET, ThisWorkbook) Then
        Application.DisplayAlerts = False
            ThisWorkbook.Sheets(strDATA_SHEET).Delete
        Application.DisplayAlerts = True
    End If

    ' Lets copy the raw data sheet.
    Set shDataRaw = ThisWorkbook.Sheets(strDATA_RAW_SHEET)
    shDataRaw.Visible = xlSheetVisible
    shDataRaw.Copy ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)

    ' Rename the sheet and hide raw data
    ActiveSheet.Name = strDATA_SHEET
    shDataRaw.Visible = xlSheetHidden

    Call TurnExtrasOn

    ' Unload the user form
    Unload Me

End Sub

' Procedure to turn extra features on
Sub TurnExtrasOn()
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
    End With
End Sub

' Procedure to turn extra features oFF
Sub TurnExtrasOff()
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationAutomatic
    End With
End Sub

' Function to check if a sheet exists
Function DoesWorksheetExist(ByVal sheetname As String, aWorkbook As Workbook) As Boolean

    On Error Resume Next
    DoesWorksheetExist = (Not aWorkbook.Sheets(sheetname) Is Nothing)
    On Error GoTo 0

End Function

I hope this helps

