+ Reply to Thread
Results 1 to 8 of 8

Preventing Save Function Until Mandatory Fields Are Completed

  1. #1
    Registered User
    Join Date
    01-04-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Preventing Save Function Until Mandatory Fields Are Completed

    Hi,

    I'm trying to prevent a excel form being saved before certain cells are filled in. Need help in VBA query. Attaching my sample form.

    Requirement 1 - If E1 is not NULL, then the user should enter the cell F1 compulsorily and sheet should return an error message as "Enter Work Status". Similarly for the entire column within the sheet and rest of the sheets in the workbook.

    Requirement 2 - If F1 is "CLOSED", then the user should enter the cell G1 compulsorily and sheet should return an error message as "Enter End Status". Similarly for the entire column within the sheet and rest of the sheets in the workbook.

    Is this possible? Any help would be greatly appreciated.

    Important - The form is protected using "Protect Sheet" option.
    Attached Files Attached Files
    Last edited by narikisas; 05-25-2015 at 10:45 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Vba help

    Unfortunately your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Preventing Save Function Until Mandatory Fields Are Completed

    Narikisas,
    The code is waitting for you
    Just update the title as moderator is requesting it and send me a message
    PCI
    - Battle without fear gives no glory - Just try

  4. #4
    Registered User
    Join Date
    01-04-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Preventing Save Function Until Mandatory Fields Are Completed

    Hi PCI,

    I have edited my title as "Preventing Save Function Until Mandatory Fields Are Completed" as soon as the moderator replied about the rules. Can you let me know if anything is missing?

    Thank you.

  5. #5
    Registered User
    Join Date
    01-04-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Preventing Save Function Until Mandatory Fields Are Completed

    Hi PCI,

    I have edited my title as "Preventing Save Function Until Mandatory Fields Are Completed" as soon as the moderator replied about the rules. Can you let me know if anything is missing?

    Thank you.

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Preventing Save Function Until Mandatory Fields Are Completed

    Here some code:
    in a module put

    Please Login or Register  to view this content.
    In ThisWorkbook put

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-04-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    24

    Re: Preventing Save Function Until Mandatory Fields Are Completed

    Hi PCI,

    Thanks for the help. It is working in the sample file i have provided to you but I am facing issues to implement the same code in my actual file because of the below reasons.

    1) I have shown the "Date", "Work Status" and "End Status" in column E, F & G in the sample file but my file has those columns Y, AE & AF. I have changed the code in which Col E is referred to Y and since AE is 6 rows after Y, I have tried changing the Column offset to 6 but showing the below error

    Run-time error '1004':
    No cells were found

    Set WkRg = Range("E2:E" & LR).SpecialCells(xlCellTypeConstants, 23)
    NbCell1 = WkRg.Cells.Count
    Set WkRg = WkRg.Offset(0, 6).SpecialCells(xlCellTypeConstants, 23)

    Can you help me modifying the code with which I can refer the correct column no?

    2) In my spreadsheet I have 5 different sheets which have different forms and the column numbers for "Date", "Work Status" and "End Status" are not the same. Can you help in creating a single code in which I can define the sheet name "Sheet1" and copy it 5 times and change the sheet name reference in the code?

    3) Lastly after creating a code which refers all the 5 sheets, would need help in popping up the mesage which tells which is not updated in which sheet.

    Thank you in advance.

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Preventing Save Function Until Mandatory Fields Are Completed

    See attached
    Now the sheet's name and the columns are parameters to informed when calling the function
    Attached Files Attached Files

+ 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