+ Reply to Thread
Results 1 to 6 of 6

User Defined Formula Function causes Excel to Freeze and Crash

  1. #1
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    User Defined Formula Function causes Excel to Freeze and Crash

    Hi all.
    I wrote the following UDF to return a string address for a discontinuous range of cells selected according to multiple criteria. It appears to work as intended when I tested it.

    But…

    If the UDF is in place, EVEN IF IT IS NOT BEING USED excel will become unresponsive each time I try to save, and then crash. Also filling in new cells with any values can trigger excel to freeze up. This is sub-optimal.

    I’m not getting any error messages, and the same issue occurs on other computers. Comment out the Function, and there is no problem.

    Can anyone point out what I am doing wrong? Any help would be GREATLY appreciated.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    If my solution helped, please consider adding Rep

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: User Defined Formula Function causes Excel to Freeze and Crash

    You have the On Error statemenst that loops.
    So go back to the drawing board and review your on error statements and don't forget to clear them

    The one really killing you is this one
    Please Login or Register  to view this content.
    The error is still there so after the Next i it goes back to the On Error statement
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Re: User Defined Formula Function causes Excel to Freeze and Crash

    Quote Originally Posted by Keebellah View Post
    You have the On Error statemenst that loops.
    So go back to the drawing board and review your on error statements and don't forget to clear them
    Yes. The idea is that if an error occurs for any cell being compared,
    the loop will skip to the end,
    clear the error,
    and reinstate error handling for the next iteration of the loop

    Quote Originally Posted by Keebellah View Post
    The one really killing you is this one
    Please Login or Register  to view this content.
    The error is still there so after the Next i it goes back to the On Error statement
    I don't understand. I thought that
    Please Login or Register  to view this content.
    clears the error. Why would the error still be there?

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: User Defined Formula Function causes Excel to Freeze and Crash

    Clear error
    Please Login or Register  to view this content.
    To end error trapping
    Please Login or Register  to view this content.
    Your trap takes you back one line of code which is the Next
    So it stays in that loop because the first line after the Next throws an error

    When coding disable the On Error ... command until you‘ve tested all the code then enable it

  5. #5
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Re: User Defined Formula Function causes Excel to Freeze and Crash

    Thanks Keebellah,

    I had been avoiding "Err.Clear" because of this description in 'Excel Macro Mastery, VBA Error Handling – A Complete Guide'
    "Note 1: Err.Clear resets the text and numbers in the error object but it does not clear the error – see On Error GoTo -1 for more information about clearing the actual error."

    I guess I had misunderstood something.

    Your trap takes you back one line of code which is the Next
    Wait, could you please confirm that. You are saying that
    Please Login or Register  to view this content.
    jumps back one line? I've never seen that in any description of the functions, nor observed it. I would have expected that to wreck a lot of other code I've written.

    Eitherway, swapping the for Err.clear HAS solved my problem, but left me feeling that I must have been misinformed on a LOT of stuff I've been reading.


    When coding disable the On Error ... command until you‘ve tested all the code then enable it
    I do exactly this. The code did exactly what wanted. I then added similar error handling that I've used a bunch of times before... And everything went to hell and couldn't understand why.

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,900

    Re: User Defined Formula Function causes Excel to Freeze and Crash

    When testing code it is good practice to add a bread moment and then from that point on step though each line of code where you think something might trigger an error and observe.

    VBA is 100% inspiration and perspiration with some very important ingredients: time, patience and creativity

+ 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. Macro and excel freeze and crash
    By chrstphaubey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-14-2017, 04:38 AM
  2. Trying to create UDF to produce different results depending on different inputs
    By forrestgump1980 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2014, 09:58 AM
  3. Use formula to create a User Defined Function
    By lindomsm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2013, 06:54 AM
  4. Enabling Macros Causes Excel To Freeze & Crash
    By alulla in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-25-2013, 12:47 PM
  5. [SOLVED] User Defined Function To Add A Zero In A Concatenated Formula
    By BanburyS in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-29-2012, 02:23 AM
  6. [SOLVED] Excel - User Defined Function Error: This function takes no argume
    By BruceInCalgary in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 04:05 PM
  7. [SOLVED] Excel "Insert Formula" dialog always call my user defined function
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2006, 10:40 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