+ Reply to Thread
Results 1 to 7 of 7

How to Stop IF Statement running continuously?

  1. #1
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    20

    How to Stop IF Statement running continuously?

    Hi guys, I have an IF statement which checks what the value in a cell is then posts a score to another cell according to the value. It works fine, however whenever I click anywhere or do other tasks on the same sheet; the true value for the IF statement keeps firing - basically it adds +2 to the cell whenever I click somewhere.

    Here's the code;

    Please Login or Register  to view this content.
    Thanks guys.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,977

    Re: How to Stop IF Statement running continuously?

    Can't diagnose out of context. Please attach your whole workbook, or at least post all of the code in this module. Is this code in Sub Worksheet_SelectionChange?
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: How to Stop IF Statement running continuously?

    Assignment 2 data.xlsm

    Here's the spreadsheet, it is for a uni assignment, I must make a questionnaire basically, the answers of which must return specific values to be calculated towards a life expectancy.

    I can't use userforms or controls..I have been instructed to only use msgbox and inputbox.

  4. #4
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: How to Stop IF Statement running continuously?

    Bump, please help.

  5. #5
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: How to Stop IF Statement running continuously?

    Hi,

    Try this.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: How to Stop IF Statement running continuously?

    Thanks, but now I have the opposite problem where it doesnt refresh at all..I think I'm going to make a msgbox saying 'Your BMI is ...' then have that value enter the box and link the assigned values to it.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,977

    Re: How to Stop IF Statement running continuously?

    This is an example of why I wanted to see all the code, and where proper code formatting for readability makes it obvious when there is a problem. Your code doesn't take full advantage of indentation. When it's indented, it's easy to see that there is an If missing in the last section. Here is all of the code from that module properly indented. I have highlighted in red where it looks like you meant to have additional code.

    Also, you have several If statements with mutually exclusive conditions. It is better to merge them into an If..Elseif..ElseIf structure as shown.
    Please Login or Register  to view this content.
    P.S. Spelling error on worksheet and in code: should be "Cholesterol"
    Last edited by 6StringJazzer; 10-04-2013 at 09:49 PM. Reason: P.S.; also corrected code for syntax

+ 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 running continuously
    By billpurdom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-07-2013, 12:29 PM
  2. Continuously running a recorded macro-Please Help
    By Nik.Kaps in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-10-2012, 07:27 AM
  3. VBA won't stop running
    By codsmith in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2011, 09:39 AM
  4. Macro to stop running at last row
    By staples in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2009, 01:52 PM
  5. Stop running all commands
    By daviddoria in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2009, 12:28 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