+ Reply to Thread
Results 1 to 9 of 9

Auto calc on, then turn off, then runtime error how to turn back on

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Auto calc on, then turn off, then runtime error how to turn back on

    Hi,

    Intially autocalc is on.............i turn off automatic calc at some point in the macro..........macro gets a runtime error for some reason that i have not anticipated......user continues to try and run macro or maybe a diff macro.......run time error results because autocalc is off (set to manual) and a calc that was supposed to happen did not.

    Any ideas how to handle this issue?

    I know the best is not to have a runtime error with autocalc set to manual........but lets suppose this does happen. then what?

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Auto calc on, then turn off, then runtime error how to turn back on

    You can put this
    Please Login or Register  to view this content.
    in immediate windows
    and hit enter

    and then change your code to handle with errrors
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Auto calc on, then turn off, then runtime error how to turn back on

    tom, thanks for the info.

    But what i was trying to get at was lets suppose a user is running the macro who is not that excel literate and they get this run time error............i dont want to have to tell them to "do something" to get autocalc set back to automatic.......i was hoping there was some way i could handle it via code

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

    Re: Auto calc on, then turn off, then runtime error how to turn back on

    Your routines should always have an error handler.
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Auto calc on, then turn off, then runtime error how to turn back on

    Hi,

    I would suggest something like this:

    Please Login or Register  to view this content.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Auto calc on, then turn off, then runtime error how to turn back on

    great information!

    Additional question:
    Do you have to have such error handling in each procedure/function (ie make this statement...........On Error GoTo Error_Handler.........in each procedure or function.....or is there a best practice kinda location to put this) or is there some way regardless of where the run time error occurs to have it always goto "Error_Handler". Where does "Error_Handler" procedure need to be .......can it just be a regular procedure in the macro?

    These may seem like dumb questions........i appologize.


    Also, why did you have the program jump to clean exit .......why not just exit. Is there some reason you would not want to do a clean exit?

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

    Re: Auto calc on, then turn off, then runtime error how to turn back on

    If you don't jump back to Clean_Exit than you don't reset the calculation mode.

    The main calling routine must have an error handler to ensure clean-up is done. I tend to have error handlers in almost every routine, especially any that change settings.

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Auto calc on, then turn off, then runtime error how to turn back on

    To my mind each procedure should have it's own error handling.

    The reason for using that structure is that if the code runs normally it will hit Clean_Exit, switch calculation back to it's original state and exit the sub. If there's an error it will throw up the error and then hit Clean_exit etc.

    Dom

  9. #9
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Auto calc on, then turn off, then runtime error how to turn back on

    thanks for the info! very helpful information. error handling such as this i have not even considered........very helpful info.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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