+ Reply to Thread
Results 1 to 6 of 6

Sub Causes Excel to Crash

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-06-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    225

    Question Sub Causes Excel to Crash

    I have a series of modules, each with one sub. At the end of one sub, it will call the next to start. I am having a problem with one specific sub in the middle, but I can't figure out why. Everytime it gets to this specific sub, Excel crashes and brings up a window that says, "Microsoft Office Excel is trying to recover your information..." This happens everytime, and the macro never completes. I didnt write the sub any different than the others, yet it is still the only one that fails. Any ideas on common things that may cause this to happen?



    All suggestions are welcome.

    Thanks for looking!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,914

    Re: Sub Causes Excel to Crash

    I suspect that you might just need to give us a little more information ... like the code.

    It's a bit like walking into a garage and saying your car breaks down but only at a certain time of the day and/or on a particular route. No car, no diagnosis.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    09-06-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    225

    Re: Sub Causes Excel to Crash

    Thanks for your response. So a previous sub copies a table into the "REPORT" worksheet on this workbook. I then use the match function to identify columns within this table. I also add helper columns. After the helper columns are added, I then filter the table as needed. Columns are then copied over to a seperate worksheet within the workbook, which creates a report. I have various other subs like this one that create other reports within the workbook, but this is the only one that is causing Excel to crash.

    Option Explicit
    
    Dim LR As Long
    Dim lClientID As Long
    Dim lLoanNumber As Long
    Dim lFHLMC As Long
    Dim lInvestor As Long
    Dim lSupervisor As Long
    Dim lRM As Long
    Dim lStatus As Long
    Dim rngData As Range
    Dim lTemplateCreation As Long
    Dim lTemplateAge As Long
    Dim lWorkbasket As Long
    Dim lSubstatus As Long
    
    'Call variables
    Dim lLMIBB As Long
    Dim lLMIBO As Long
    Dim lWSPOK As Long
    Dim lIUPAC As Long
    Dim lIUPDC As Long
    Dim l1SPOK As Long
    Dim l1NOCN As Long
    Dim lWNOCN As Long
    
    'Helper Columns
    Dim cLastCall As Long
    Dim cLastCallDays As Long
    Dim cAfterTemplate As Long
    
    
    
    
    Sub Last_Call_Pre()
    
    
    
    
    'Assigning Variables
    
    With Worksheets("REPORT").Activate
    
        lClientID = Application.WorksheetFunction.Match("PARTITIONCD", Range("1:1"), 0)
        lLoanNumber = Application.WorksheetFunction.Match("LOAN_NUMBER", Range("1:1"), 0)
        lFHLMC = Application.WorksheetFunction.Match("FHLMC_T", Range("1:1"), 0)
        lInvestor = Application.WorksheetFunction.Match("INVESTOR_TYPE", Range("1:1"), 0)
        lSupervisor = Application.WorksheetFunction.Match("DW_ASSIGNEDRM_EMP_MGR", Range("1:1"), 0)
        lRM = Application.WorksheetFunction.Match("DW_ASSIGNEDRM_EMP_NAME", Range("1:1"), 0)
        lStatus = Application.WorksheetFunction.Match("LOSS_MIT_STATUS_CODE", Range("1:1"), 0)
        lTemplateCreation = Application.WorksheetFunction.Match("LOSS_MIT_SET_UP_DATE", Range("1:1"), 0)
        lTemplateAge = Application.WorksheetFunction.Match("TEMPLATE_AGE", Range("1:1"), 0)
        lWorkbasket = Application.WorksheetFunction.Match("WORKBASKET", Range("1:1"), 0)
        lSubstatus = Application.WorksheetFunction.Match("SUBSTATUS", Range("1:1"), 0)
    
    
    'Call Variables
        lLMIBB = Application.WorksheetFunction.Match("LMIBB", Range("1:1"), 0)
        lLMIBO = Application.WorksheetFunction.Match("LMIBO", Range("1:1"), 0)
        lWSPOK = Application.WorksheetFunction.Match("WSPOK", Range("1:1"), 0)
        lIUPAC = Application.WorksheetFunction.Match("IUPAC", Range("1:1"), 0)
        lIUPDC = Application.WorksheetFunction.Match("IUPDC", Range("1:1"), 0)
        l1SPOK = Application.WorksheetFunction.Match("1SPOK", Range("1:1"), 0)
        l1NOCN = Application.WorksheetFunction.Match("1NOCN", Range("1:1"), 0)
        lWNOCN = Application.WorksheetFunction.Match("WNOCN", Range("1:1"), 0)
        
        
    
    'Helper Column Variables
        cLastCall = Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Column
        cLastCallDays = Cells(1, cLastCall).Offset(, 1).Column
        cAfterTemplate = Cells(1, cLastCallDays).Offset(, 1).Column
    
        LR = Range("A" & Rows.Count).End(xlUp).Row
        Set rngData = Range("A1").CurrentRegion
    
    
    
    'FUNCTIONS
    
    
    'Max Last Call 
        With Range(Cells(2, cLastCall), Cells(LR, cLastCall))
                .FormulaR1C1 = "=MAX(RC" & lLMIBB & ", RC" & lLMIBO & ", RC" & lWSPOK & ", RC" & lIUPAC & _
                ", RC" & lIUPDC & ", RC" & l1SPOK & ", RC" & l1NOCN & ", RC" & lWNOCN & ")"
        End With
    
    
    'Aging Since Last Call
        With Range(Cells(2, cLastCallDays), Cells(LR, cLastCallDays))
                .FormulaR1C1 = "=IF(RC" & cLastCall & " ="""", """", Today()- RC" & cLastCall & ")"
                .NumberFormat = "0"
                .Value = .Value
        End With
    
    
    'Equation that MAX call > template creation
        With Range(Cells(2, cAfterTemplate), Cells(LR, cAfterTemplate))
            .FormulaR1C1 = "=AND(RC" & cLastCall & " < RC" & lTemplateCreation & ")"
        End With
    
    End With
    
    'Filters
    
    With Worksheets("REPORT")
    
        rngData.AutoFilter Field:=lStatus, Criteria1:="A"
        rngData.AutoFilter Field:=cAfterTemplate, Criteria1:="FALSE"
        rngData.AutoFilter Field:=lWorkbasket, Criteria1:=Array("CustomerContact", "DocChasing", "QA", "PlanBreak"), Operator:=xlFilterValues
        rngData.AutoFilter Field:=lSubstatus, Criteria1:="<>" & "Confirmation of Denial"
        rngData.AutoFilter Field:=cLastCall, Criteria1:="<" & Date - 2
    
    'Client ID
    
        LR = .Cells(.Rows.Count, lClientID).End(xlUp).Row
        If LR > 1 Then
            .Range(.Cells(2, lClientID), .Cells(LR, lClientID)).Copy _
                    Sheets("Last Call (Pre Dec)").Range("A3")
        End If
    
    
    'Loan Number
    
        LR = .Cells(.Rows.Count, lLoanNumber).End(xlUp).Row
        If LR > 1 Then
            .Range(.Cells(2, lLoanNumber), .Cells(LR, lLoanNumber)).Copy _
                    Sheets("Last Call (Pre Dec)").Range("B3")
        End If
    
    
    'Freddie
    
    
        LR = .Cells(.Rows.Count, lFHLMC).End(xlUp).Row
        If LR > 1 Then
            .Range(.Cells(2, lFHLMC), .Cells(LR, lFHLMC)).Copy _
                    Sheets("Last Call (Pre Dec)").Range("C3")
        End If
    
    
    'Investor
    
        LR = .Cells(.Rows.Count, lInvestor).End(xlUp).Row
        If LR > 1 Then
            .Range(.Cells(2, lInvestor), .Cells(LR, lInvestor)).Copy _
                    Sheets("Last Call (Pre Dec)").Range("D3")
        End If
    
    
    'Supervisor
    
        LR = .Cells(.Rows.Count, lSupervisor).End(xlUp).Row
        If LR > 1 Then
            .Range(.Cells(2, lSupervisor), .Cells(LR, lSupervisor)).Copy _
                    Sheets("Last Call (Pre Dec)").Range("E3")
        End If
    
    
    'RM
    
        LR = .Cells(.Rows.Count, lRM).End(xlUp).Row
        If LR > 1 Then
            .Range(.Cells(2, lRM), .Cells(LR, lRM)).Copy _
                    Sheets("Last Call (Pre Dec)").Range("F3")
        End If
    
    
    'Workbasket
    
        LR = .Cells(.Rows.Count, lWorkbasket).End(xlUp).Row
        If LR > 1 Then
            .Range(.Cells(2, lWorkbasket), .Cells(LR, lWorkbasket)).Copy _
                    Sheets("Last Call (Pre Dec)").Range("G3")
        End If
    
    
    'Substatus
    
        LR = .Cells(.Rows.Count, lSubstatus).End(xlUp).Row
        If LR > 1 Then
            .Range(.Cells(2, lSubstatus), .Cells(LR, lSubstatus)).Copy _
                    Sheets("Last Call (Pre Dec)").Range("H3")
        End If
    
    
    'Days Since Last Call
    
        LR = .Cells(.Rows.Count, cLastCallDays).End(xlUp).Row
        If LR > 1 Then
            .Range(.Cells(2, cLastCallDays), .Cells(LR, cLastCallDays)).Copy _
                    Sheets("Last Call (Pre Dec)").Range("I3")
        End If
    
    
    End With
    
    
    'Delete extra column and Clears filter on REPORT
    
    With Worksheets("REPORT")
    
        ActiveSheet.ShowAllData
    
        Columns(cAfterTemplate).Select
        Selection.Delete
    
        Columns(cLastCallDays).Select
        Selection.Delete
    
        Columns(cLastCall).Select
        Selection.Delete
        
        .Range("A1").Select
    
    End With
    
        Sheets("Last Call (Pre Dec)").Select
    
    
    'Range Filldowns
    
        With Worksheets("Last Call (Pre Dec)")
        
            'Last Call Aging Range
            With .Range("J3", Range("I" & Rows.Count).End(xlUp).Offset(, 1))
                .FormulaR1C1 = "=IF(RC[-1] < 6, ""1-5 Days"", If(AND(RC[-1] >=6, RC[-1] <=10), ""6-10 Days"", ""> 10 Days""))"
                .Value = .Value
            End With
    
        End With
    
    Call Last_Call_Post
    
    End Sub

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: Sub Causes Excel to Crash

    it's easier to rcv help if you upload a test file having some of your subs, such as msgbox instead of yr code, but that sub which crashes excel...perhaps you can create the erorr
    Last edited by john55; 12-04-2013 at 12:41 PM. Reason: OP has posted code
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  5. #5
    Forum Contributor
    Join Date
    09-06-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    225

    Re: Sub Causes Excel to Crash

    So after stepping through one line at a time, it seems to be crashing at this line every time:

        lWorkbasket = Application.WorksheetFunction.Match("WORKBASKET", Range("1:1"), 0)
    It's weird because if I drag the prompt to skip over it, then it doesnt crash. If i remove the line, it still crashes at that same spot... i dont get it. Does this help anyone understand what may be occurring?

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,914

    Re: Sub Causes Excel to Crash

    If you get an error at that point, it probably means that it isn't finding the thing that it's trying to match. In this case, the text "WORKBASKET". That probably means that whatever is on the worksheet isn't exactly the same as what you're looking for ... maybe a trailing space.

    You could check and fix the data or put an * on the end of the text you are searching for to wildcard it.

    If it's not that, please don't ask the question again without posting a sample workbook that demonstrates the problem.

    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel 2007 : Excel Crash On Save
    By aussiemcgr in forum Excel General
    Replies: 0
    Last Post: 07-27-2010, 01:04 PM
  2. excel vba causes crash
    By Code Flunkie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2010, 05:34 PM
  3. Excel Crash - Help!
    By Delbert in forum Excel General
    Replies: 13
    Last Post: 12-13-2005, 06:10 PM
  4. Excel VBA macro crash
    By Patrick in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-13-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1