+ Reply to Thread
Results 1 to 4 of 4

Worksheet_Calculate randomly causing issues

  1. #1
    Forum Contributor
    Join Date
    07-13-2015
    Location
    Quebec, Canada
    MS-Off Ver
    2013
    Posts
    232

    Worksheet_Calculate randomly causing issues

    Hello,

    I made a code on Worksheet_Calculate that only serves for the sheet called "Input". I started with a condition:

    If ActiveSheet.Name = "Input" Then
    stuff
    End If

    So I have no issues when in another sheet, at least. However, sometimes, when I edit something on the sheet "Input", I get an error, although nothing is wrong. (e.g. it redirects me to an "else" statement in the code and there's nothing wrong with the code...) If I put it in a button instead, it does nothing wrong, but I need it to trigger everytime someone edit the page.

    So here's what I'm doing:

    I want a code that triggers when someone a cell in the following range: F10:I17. It makes buttons appear or disappear, depending on the total in that range. Example:

    problem.png

    As you can see, every row has 2 button associated to it; if the total is at least one for the row, they appear. Here's my code (it works):

    Please Login or Register  to view this content.
    (EDIT: Yeah forget about the If 1 = 2, that was just me trying to stop the code from working for some time, it's just a comment anyway)

    With the On error clause, every now and then when I do anything on the file, the msgbox appears and everything freezes, excel crashes. What's going on? all those objects exist and both those sheets exist, so there's no worries to have about that. I therefore am thinking it is caused by Worksheet_Calculate doing weird things I don't understand. Therefore..

    1- Does anyone have a way to fix this? OR
    2- Does anyone see another way to exactly what I'm trying to do, without using Worksheet_calculate?

    Hope it's clear enough!

    Thanks
    Last edited by Jdevil; 07-16-2015 at 08:26 AM.

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Worksheet_Calculate randomly causing issues

    The Calculate event isn't the place for what you're trying to do. I'm assuming that your code is triggering the event, creating a recursive loop that is sure to blow up. Put it in the Change event of the Input sheet, which fires only when a change is made on that sheet, with no need to check the sheet name, or to reference it. You can also eliminate all the Sheets("Champs") reference with a single With statement. Use the Intersect statement to determine if the entry was in the desired range. Here's the starter code:
    Please Login or Register  to view this content.
    Last edited by natefarm; 07-15-2015 at 05:23 PM.
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Forum Contributor
    Join Date
    07-13-2015
    Location
    Quebec, Canada
    MS-Off Ver
    2013
    Posts
    232

    Re: Worksheet_Calculate randomly causing issues

    I can't really use "With" that simply because the code actually uses two sheets for some time, I could probably name things to make it simplier, but that's minor considering..

    You entirely solved my problem with the "Not intersect" thing in Worksheet_Change. Works wonder.

    Thanks a lot!

  4. #4
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Worksheet_Calculate randomly causing issues

    You're welcome. If you group your Ifs by applicable sheet, and then use separate Withs to apply to each group, it should still work. It's more efficient, easier to read, and easier to maintain.

    Glad I could help.

+ 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] Slicer cache causing issues in VBA
    By Tip1985 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2015, 03:53 AM
  2. What might be causing events to become disabled randomly?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-10-2015, 12:58 PM
  3. Volatile Functions causing issues
    By penfold1992 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-21-2014, 10:40 AM
  4. [SOLVED] Complex combining of formulas causing me issues
    By phpolicylady in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-10-2014, 10:14 AM
  5. External Links Causing Issues
    By kushalb in forum Excel General
    Replies: 4
    Last Post: 05-23-2011, 06:27 AM
  6. Negative value causing issues
    By Speedbird1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-01-2008, 10:24 AM
  7. [SOLVED] If then statement causing value issues in Macros
    By ssciarrino in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2005, 02:10 PM

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