Excel Crashes Initializing 2nd Userform

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have an open userform (uf_create_wo1) in which the user presses a button to launch some code.

The code does a variety of things, including opening and hiding a second workbook holding data. After a bunch of processing and user prompts, a second userform (userform1) is attempted to be opened.

It is at the initialization of that second userform that Excel crashes.

I am hoping that someone is able to identify the issue that may be causing Excel to become unstable and crash.

Here is the code (from module one called from the first userform) opening the second userform ...

Rich (BB code):
Sub GetUniques()

    'analyses data in schedule.csv determining range of dates within database and the number of records unique to those dates

    
    Dim d As Object, c As Variant, i As Long, lr As Long
    Dim temp_ws As Worksheet
    Dim wb1 As Workbook
    Dim v1 As Long
    Dim strFilename As String
    Dim msg1 As String
    Dim rng1 As Range
    Dim oFS As Object
    Dim ui2 As String
    Dim data_file_list As Name
    Dim x As Boolean

    Application.ScreenUpdating = False

'On Error GoTo ErrorTrap
    With Workbooks("schedule.csv").Worksheets("schedule")
    Set d = CreateObject("Scripting.Dictionary")
    lr = .Cells(Rows.Count, 1).End(xlUp).row
    c = .Range("M1:M" & lr)
    For i = 1 To UBound(c, 1)
        d(c(i, 1)) = 1
    Next i
    End With

    Set wb1 = Workbooks("schedule.csv")                                                 'a temporary worksheet for statistical presentation
    Set temp_ws = wb1.Worksheets.Add
    temp_ws.Name = "temp_ws"
    strFilename = "H:\PWS\Parks\Parks Operations\Sports\Sports15\CLASS_DUMP\schedule.csv"
    Set oFS = CreateObject("Scripting.FileSystemObject")

    With temp_ws
    
        'create headers
        .Range("A1") = "CLASS DATE"
        .Range("B1") = "DATE SELECTION"
        .Range("C1") = "RECORDS"
        .Range("D1") = "FILE DATE"
        .Range("E1") = "SERIAL DATE"
        .Range("A2").Resize(d.Count) = Application.Transpose(d.keys) 'paste the unique dates found in 'getuniques' function [module2]
    
        'populate columns
        v1 = WorksheetFunction.Count(.Range("A:A"))
        For i = 1 To v1
            .Range("B" & i + 1) = Format(.Range("A" & i + 1), "ddd dd-mmm") 'date format 1
            .Range("C" & i + 1) = WorksheetFunction.CountIf(Workbooks("schedule.csv").Worksheets("schedule").Range("M:M"), .Range("A" & i + 1)) 'number of raw records for that date
            .Range("E" & i + 1) = .Range("A" & i + 1) 'serial date format
            .Range("D" & i + 1) = Format(.Range("E" & i + 1), "dd-mmm") 'date format 2
        Next i
    
        'create string list
        For Each rng1 In .Range("A2:A" & v1 + 1)
            msg1 = msg1 & vbLf & .Cells(rng1.row, 1) & " (" & rng1.offset(0, 2) & " records" & ")"
        Next rng1
        Workbooks("Sports15b.xlsm").Names.Add Name:="data_file_list", RefersTo:="=OFFSET('[" & wb1.Name & "]" & temp_ws.Name & "'!$B$1,1,0,count('[" & wb1.Name & "]" & temp_ws.Name & "'!$A:$A),2)"
        
        'create message box
        ui2 = MsgBox("This report created on " & Chr(13) & Chr(13) & oFS.GetFile(strFilename).Datelastmodified & Chr(13) & Chr(13) & _
            "contains data for " & v1 & " date(s):" & vbLf & msg1 & Chr(13) & Chr(13) & "Press YES to proceed with this schedule, or " & Chr(13) & _
            "select NO to create a new schedule.", vbQuestion + vbYesNo, "SCHEDULE CONTENTS")
            
        If ui2 = vbYes Then
            'Workbooks("Sports15b.xlsm").Activate
            'Application.EnableEvents = True
            UserForm1.Show
        Else
            Workbooks("schedule.csv").Close savechanges:=False
            Application.EnableEvents = True
            Exit Sub
        End If
    
    End With

End Sub

And the initialization code from userform1...
Rich (BB code):
Private Sub UserForm_Initialize()
    With UserForm1.ListBox1
        .Clear
        .ColumnCount = 2
        .List = Range("data_file_list").Value
        .ListStyle = fmListStyleOption
        .MultiSelect = fmMultiSelectMulti
        .Value = 0
        .Locked = True
    End With
End Sub

Thank you all in advance. If I am needing to add additional information, please let me know.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Userform uf_create_wo1 's showmodal property was set to false. Setting it to true appears to have stopped Excel from crashing.
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top