+ Reply to Thread
Results 1 to 19 of 19

Prevent Excel workbook closing saving if the mandatory cells not filled in

  1. #1
    Registered User
    Join Date
    02-06-2017
    Location
    Guildford
    MS-Off Ver
    2013
    Posts
    9

    Prevent Excel workbook closing saving if the mandatory cells not filled in

    Hi All,

    I am new to this forum - greetings to everybody here. Please kindly help me with the below mentioned query.

    My query:

    I have Excel workbook which needs to be filled in correctly. If user fills in any cell of column B, then he/she would need to fill in corresponding cells (same row) of columns E, F, I, J, K, L, & Q respectively. If the cells are not filled in, user will not be able to save or close the Workbook (active sheet). I am not good at visual basic, your help is highly appreciated. Please also guide me on if need be how do I add more cells of other columns than mentioned above.

    I tried to attach the documents, not sure if it will work.



    Kind regards,

    Table screenshot.docx
    FIR ladders 2016 2.xlsx

  2. #2
    Registered User
    Join Date
    01-20-2017
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    I will take a look at the file and see what I can do.
    Last edited by BillyRaySpivy; 02-07-2017 at 07:46 AM.

  3. #3
    Registered User
    Join Date
    02-06-2017
    Location
    Guildford
    MS-Off Ver
    2013
    Posts
    9

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    Here it goes. Please let me know if it opens.

    FIR ladders 2016 2.xlsx

  4. #4
    Registered User
    Join Date
    02-06-2017
    Location
    Guildford
    MS-Off Ver
    2013
    Posts
    9

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    Thanks Billy.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    welcome to the forum
    ...and you can try this too
    workbook attached

    VBA is in the workbook module

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  6. #6
    Registered User
    Join Date
    01-20-2017
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    Kev,

    Would it be possible to highlight the cells red until they are filled to remind the user?

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    I realised after posting that reference to the worksheet was omitted
    (it worked - but could cause a problem if workbook contains more than one sheet!!)

    So replace the code for ValueCheck with:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-06-2017
    Location
    Guildford
    MS-Off Ver
    2013
    Posts
    9

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    Kev,

    Many thanks for the sheet - Genius! Couple of questions:

    1. I replaced the code with the one you sent just now, received compilation error.
    2. If I change the name of sheets in the workbook or copy the same sheet in the workbook, will the code be working on those sheets as well?

    Could you kindly replace the coding and send the workbook to me.

    Best regards,

    Kash

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    This is the code amended to make the empty cells RED
    Try in attached workbook

    Note that VBA now uses SpecialCells(xlCellTypeBlanks) to identify empty cells without looping through them


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kev_; 02-07-2017 at 09:40 AM.

  10. #10
    Registered User
    Join Date
    01-20-2017
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    I tried the updated code to make the cells red and nothing seems to happen. If you have a chance could you please check it out?

  11. #11
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    ????

    I have downloaded the file that I posted and it works fine for me
    Are you opening the correct file after download?

  12. #12
    Registered User
    Join Date
    01-20-2017
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    Sorry about that it was the wrong file. Thank you for being such a great help.

  13. #13
    Registered User
    Join Date
    01-20-2017
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    I did try it again and noticed that if the contents of the cells are emptied the ranges stay red. It might be useful to have another condition if the user decides to delete the contents.

  14. #14
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    No problem. We all do it!
    Cells only stays red until you try to close or save file again - keeping the red there should remind the users to get it right next time!!

    I suggest you turn the problem on its head before things get messy:

    How about:
    - when value is input in column B THEN
    - the critical cells are formatted red UNTIL
    - a value is placed in each critical cell, and its formatting returns to normal

    And trigger the "before close" and "before save" with the rule that any red cells results in no close/no save

  15. #15
    Registered User
    Join Date
    02-06-2017
    Location
    Guildford
    MS-Off Ver
    2013
    Posts
    9

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    Hi Kev,

    Many thanks for your genius work - It looks good. If I copy/move the same sheet in the workbook or change the name of the sheet in the workbook, will the code still work?

    Regards,

    Kash

  16. #16
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    see post#9 - the clue was in this line:
    Please Login or Register  to view this content.
    Will there be more than one sheet in the workbook to which this code needs to apply?
    If there is, then need to loop through all the sheets that apply.
    Let me know...


    thanks
    Kev

  17. #17
    Registered User
    Join Date
    02-06-2017
    Location
    Guildford
    MS-Off Ver
    2013
    Posts
    9

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    Hi Kev,

    Thanks - Yes there will be more than one sheet in the same workbook, one sheet per week.

    Best regards,

    Kash

  18. #18
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    Ok - are there any sheets that should be excluded?

  19. #19
    Registered User
    Join Date
    02-06-2017
    Location
    Guildford
    MS-Off Ver
    2013
    Posts
    9

    Re: Prevent Excel workbook closing saving if the mandatory cells not filled in

    No, there are no sheets that would need to be excluded.

    Many thanks.

+ 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. Mandatory Fields and Closing/Saving Workbooks
    By JCRoessler14 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2016, 10:31 AM
  2. Prevent saving unless the data is filled
    By bhavesh.kangokar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2015, 09:11 AM
  3. [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
  4. VBA to prevent saving if any cells are filled with a certain color
    By ks26 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-29-2014, 04:53 PM
  5. Mandatory cells if another is filled
    By jdixon825 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2014, 10:32 PM
  6. [SOLVED] How to make it IMPOSSIBLE TO CLOSE Workbook until mandatory cells r nt filled?
    By Scofield24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2013, 05:31 AM
  7. [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

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