+ Reply to Thread
Results 1 to 5 of 5

Conflict in Code Crashing Excel when Sheets Deleted

  1. #1
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Conflict in Code Crashing Excel when Sheets Deleted

    I have a macro that cycles through sheets in a workbook and deletes them. However, excel crashes on the Delete command and i don't know how to fix it.

    I have an Index page (excluded from the delete process) at the start of the workbook.

    This index page is basically a table of contents. It lists all the sheets in the workbook, the sheet name, and the value of a specific cell in the sheet. This is done using UDFs. However, the UDFs use the Sheets object of the workbook so when my other macro goes through the delete process i think these UDFs are crashing excel.

    I've tried adding
    Please Login or Register  to view this content.
    to the start of my "delete" macro but it doesn't help. Is there anything i can do or am i going to have to rethink my solution?

    Many thanks

    J

    The Culprits FYI:

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Function TESTTITLE(IndexNumber As Integer, NamedRange As String)

    Please Login or Register  to view this content.
    EDIT: An example formula from my index page

    Please Login or Register  to view this content.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Conflict in Code Crashing Excel when Sheets Deleted

    What exactly do you mean by "crashing Excel"? If you mean the program literally crashes, rather than a simple code error, that shouldn't happen simply from that - the functions would just return errors when they recalculate.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Conflict in Code Crashing Excel when Sheets Deleted

    Quote Originally Posted by romperstomper View Post
    What exactly do you mean by "crashing Excel"? If you mean the program literally crashes, rather than a simple code error, that shouldn't happen simply from that - the functions would just return errors when they recalculate.
    yup. Full on crash. Asks to send an error report, asks if you want to re-open at the last autosave. Reboots the instance of Excel.

    Anyway for other people's info, i fixed it (don't know how though really!)

    I've taken the delete code out of the Private_Sub of the command button within the sheet and instead put it into a module and got the command button to call it.

    Also, when this started happening i bookended my code with application calculation manual and then automatic. BUT, my final line was a full calculation (my thinking was to force Excel to recalculate everything)

    By removing the command to recalculate everything and also putting the code in its own module the crash no longer occurs. My final line of code on the delete macro simply sets the application calculation back to automatic.

    I have noticed though, that the values in the cells containing the UDFs calculate when the delete macro executes WITHOUT the command to calculatefull. So perhaps this is where i was generating a conflict...

    Anyway, these steps appear to have sorted it for one reason or another!

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Conflict in Code Crashing Excel when Sheets Deleted

    Where was the button?

  5. #5
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Conflict in Code Crashing Excel when Sheets Deleted

    The button was in the same sheet that the UDFs were calculating on, which made me think there may be an issue there...

+ 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. [SOLVED] How can I streamline/ speed up my code- it is currently crashing excel
    By strud in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-14-2013, 08:10 AM
  2. Excel 2010 crashing when running macros....my code?
    By dietcoke802 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-20-2013, 05:56 PM
  3. Macro to Copy Sheets and Save As New Workbook Crashing Excel
    By JamieAtJack in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2012, 08:19 PM
  4. Code to detect if sheets have been moved or deleted
    By Newbie_Nick in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-19-2010, 03:29 AM
  5. [SOLVED] deleted work sheets - Excel
    By Beth in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-25-2006, 05:10 PM

Tags for this Thread

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