+ Reply to Thread
Results 1 to 13 of 13

Make multiple cell input mandatory if initial cell has input.

  1. #1
    Registered User
    Join Date
    11-02-2011
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Make multiple cell input mandatory if initial cell has input.

    Have a spreadsheet that I require a user to fill out nightly. Basically, they keep forgetting to fill in necessary information. I want to force them to put information in Cells F8, G8 if they put their initials in cell E8.

    Also, if they put a value of No in cell H8, I want for them to complete cells D18, E18 and
    F18. If they don't complete all the cells, I don't want the Spreadsheet to save and\or close.

    If anyone is a vb wizard I'd appreciate your help, I also need to know how to replicate the code for sequence's of other cells as well.

    Thanks
    Last edited by dwporter; 11-02-2011 at 03:58 PM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Desperate need of some VB script help.

    Try pasting this into the ThisWorkbook tab in the VB editor (Alt F11)

    Please Login or Register  to view this content.
    Martin

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Make multiple cell input mandatory if initial cell has input.

    Try

    Please Login or Register  to view this content.
    My mistake

  4. #4
    Registered User
    Join Date
    11-02-2011
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Make multiple cell input mandatory if initial cell has input.

    Still need some help. Code needs to work as follows:

    If cell E8 is blank, the f8, g8, ahd h8 can also be blank but if e8 has data entered in the cell then f8, g8, and h8 has to have mandatory data. Also if H8 value is "no" then cells
    d18, e18, and f18 must have mandatory input as well.

    So ... if e8 has data, f8 is mandatory input , g8 in mandatory input, and h8 is mandatory input, but if h8 input is "yes" then save\close worksheet, otherwise if h8 is "no" then cells d18, e18 and f18 must have mandatory input, then save\close spreadsheet

  5. #5
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Make multiple cell input mandatory if initial cell has input.

    Try

    Please Login or Register  to view this content.
    If the code fails to run when save is attempted, you may need to reset the EnableEvents to True.

    Do this by opening the immediate window in the VBA editor (Alt G) and typing in

    Please Login or Register  to view this content.
    followed by a return.

    To get the same behaviour on close, but the same code into the BeforeClose event.

    Please Login or Register  to view this content.
    If you still are experiencing problems, it would be useful to post the actual workbook as there may be something in there which is not apparent from a distance.

  6. #6
    Registered User
    Join Date
    11-02-2011
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Make multiple cell input mandatory if initial cell has input.

    I'm still unable to achieve any type results. I can save or close the document after completing the initial field E8. I've attached the spreadsheet. Thanks for all your assistance
    Attached Files Attached Files

  7. #7
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Make multiple cell input mandatory if initial cell has input.

    Try

    Please Login or Register  to view this content.
    You have cells that appear to be empty but actually contain a single space. The code was detecting these as full. I've added a TRIM function to remove whitespace - hopefully this will help.

  8. #8
    Registered User
    Join Date
    11-02-2011
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Talking Re: Make multiple cell input mandatory if initial cell has input.

    Works GREAT!!!!!

    One last request.Can you show me how to replicate the code for the other remaining rows in the spreadsheet...row 9(e,f,g,h) row 10(e,f,g,h) etc.

  9. #9
    Registered User
    Join Date
    11-02-2011
    Location
    Roanoke, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Make multiple cell input mandatory if initial cell has input.

    I just duplicated the code as follows. It seems to work fine.

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = False
    Application.EnableEvents = True

    If Trim(Range("E8")) <> "" Then
    If Trim(Range("F8")) = "" Then Cancel = True
    If Trim(Range("G8")) = "" Then Cancel = True
    If Trim(Range("H8")) = "" Then Cancel = True
    End If

    If Range("H8") = "No" Then
    If Trim(Range("D18")) = "" Then Cancel = True
    If Trim(Range("E18")) = "" Then Cancel = True
    If Trim(Range("F18")) = "" Then Cancel = True
    End If

    If Trim(Range("E9")) <> "" Then
    If Trim(Range("F9")) = "" Then Cancel = True
    If Trim(Range("G9")) = "" Then Cancel = True
    If Trim(Range("H9")) = "" Then Cancel = True
    End If

    If Range("H9") = "No" Then
    If Trim(Range("D18")) = "" Then Cancel = True
    If Trim(Range("E18")) = "" Then Cancel = True
    If Trim(Range("F18")) = "" Then Cancel = True
    End If

    If Cancel = True Then MsgBox "Please fill in all the cells required."

    End Sub

  10. #10
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Make multiple cell input mandatory if initial cell has input.

    Looks good.

    You might consider giving a more specific message like below.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-22-2017
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    10

    Re: Make multiple cell input mandatory if initial cell has input.

    hey there,

    I know it's an old post but really useful. I just have one question.
    How can i select a whole column? I've tried everything but i cannot find something that works...
    Could you help me with that?

    Thanks,

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Make multiple cell input mandatory if initial cell has input.

    Joceau welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  13. #13
    Registered User
    Join Date
    11-22-2017
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    10

    Re: Make multiple cell input mandatory if initial cell has input.

    No problem sorry :-)

+ 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