+ Reply to Thread
Results 1 to 7 of 7

Deactivate Event only on if statment

  1. #1
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Question Deactivate Event only on if statment

    I would like to write a if statment within the worksheet_deactivate event that only allows the user to deactivate the worksheet when something is true.

    Please Login or Register  to view this content.
    If the above is not the case, then do not allow the user to deactivate the worksheet.


    EDIT: and also display a msgbox as to why they are unable to deactivate the worksheet.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Deactivate Event only on if statment

    Hi Clemson,

    I don't believe you can (or should want to) do this. The Deactivate event (workbook or worksheet) don't accept the argument "Cancel as Boolean" like the Workbook_BeforeSave and _BeforeClose events do.

    I'd recommend you prevent them from saving if those conditions are met, but not changing sheets. In that case, use the Workbook_BeforeSave event and add the line
    Please Login or Register  to view this content.
    to that procedure, e.g.
    Please Login or Register  to view this content.
    You can add other code, such as a message box telling the user why the save was canceled.
    Last edited by Paul; 03-30-2012 at 04:33 PM.

  3. #3
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: Deactivate Event only on if statment

    Thanks for the heads up Paul. I appreciate your advice.

    But this document is a tool for preparing proposals and contracts and this information is critical. I do not want the user to move from this page (worksheet) if that criteria isn't meet because if they do and continue to use the tool (without the above being true) and work with it - then that can be bad).

    So you're saying that cant be done?

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Deactivate Event only on if statment

    You can't use the Cancel = True method, but you could use something like:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: Deactivate Event only on if statment

    Wonderful - Thank you. I do believe this works just what I asked for.

    Now - can I throw a wringle in there?

    I want to change the if statment to be just like it is, but ONLY compare it to Range("E2") when there is a value in it. when its blank or zero, I only want B4 to be compared to B2 and I need more help with that code.

  6. #6
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: Deactivate Event only on if statment

    Maybe I got it:

    Please Login or Register  to view this content.
    Thanks for all the help!!!

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Deactivate Event only on if statment

    You're welcome! Glad to see you sorted out the last bit on your own. If you wouldn't mind, please mark the thread as Solved by going to the first post and clicking 'Thread Tools' in the bar above it, then selecting 'Mark this thread as solved.'

    Thanks!

    EDIT: I see you've already done that too! Wonderful!

+ 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