+ Reply to Thread
Results 1 to 8 of 8

Prevent Workbook from closing when value from one cell is missing & another cell is not

  1. #1
    Registered User
    Join Date
    09-13-2017
    Location
    United States
    MS-Off Ver
    MS Office 365
    Posts
    43

    Prevent Workbook from closing when value from one cell is missing & another cell is not

    Hi,

    So I have been working to create a vba program that will prevent the user from closing the workbook if the first cell is not empty and the cell below is, or the first cell is empty but the cell below is not. If both cell are empty or both cell are not empty, then the workbook will save and close.

    What I want to do is to apply this for the entire row or at least a range if possible. Checking each of the column. If you have any idea please help. Thank you.

    Here is the code that I have been working on and trying to tweak to apply to entire row.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Prevent Workbook from closing when value from one cell is missing & another cell is no

    This code will check A1 against A2, B1 against B2 etc over to column G.

    If A1 and A2 both either have data or both don't have data it will continue to B1 and B2 and run the same check.

    If at any time one has data and the other is blank you get a message saying there is a problem with those two cells.
    Please Login or Register  to view this content.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Registered User
    Join Date
    09-13-2017
    Location
    United States
    MS-Off Ver
    MS Office 365
    Posts
    43

    Re: Prevent Workbook from closing when value from one cell is missing & another cell is no

    Hi Skywriter,

    I have applied your code and got this:
    Please Login or Register  to view this content.
    When I ran this code, I don't get an error message when I just fill in A1 cell. I put this in Sheet1. Do you know what is happening?

    Thank you

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Prevent Workbook from closing when value from one cell is missing & another cell is no

    Are you going to tell us what the error is?

    How are you calling the code?

  5. #5
    Registered User
    Join Date
    09-13-2017
    Location
    United States
    MS-Off Ver
    MS Office 365
    Posts
    43

    Re: Prevent Workbook from closing when value from one cell is missing & another cell is no

    My apology, I meant the message box when I have one cell empty and the next row cell filled. I am not sure what you mean by calling the code but I was hoping that it would automatically occur when I close the Excel Application

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Prevent Workbook from closing when value from one cell is missing & another cell is no

    Sub Test was just a made up title.

    The body of the code was meant to be put into the workbook before close event of the thisworkbook class module.

    The reason I asked how you were calling it is because you added an argument to the first line of the code that I wrote, which means you have to call the code and pass in a value for cancel.

    I put the cancel = true line in there under the assumption you would use it in the workbook event code as you did with the code you originally posted, it was just to give you an idea of where to put that line.

  7. #7
    Registered User
    Join Date
    09-13-2017
    Location
    United States
    MS-Off Ver
    MS Office 365
    Posts
    43

    Re: Prevent Workbook from closing when value from one cell is missing & another cell is no

    It worked!!! Thank you Skywriter for all the help you provided for my dilemma with my code. .

  8. #8
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Prevent Workbook from closing when value from one cell is missing & another cell is no

    My pleasure, thanks for the feedback.

+ 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. Require Entry in Cell /Prevent COUNT if Missing
    By tdale in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-18-2015, 06:05 PM
  2. [SOLVED] Prevent a workbook from closing if any cells are unlocked
    By ks26 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-05-2014, 12:04 PM
  3. [SOLVED] Prevent user from closing worksheet if cell is blank
    By maryren in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-15-2013, 12:11 PM
  4. [SOLVED] Prevent closing of a workbook if condition is met - code included
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2013, 10:24 AM
  5. Macro to prevent closing of workbook depending on certain criteria
    By tysonz1987 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 02:30 PM
  6. [SOLVED] Prevent closing workbook unless specific cells have data
    By ardais in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2012, 03:31 PM
  7. Prevent closing of one workbook when two are open
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-02-2009, 11:45 AM

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