+ Reply to Thread
Results 1 to 5 of 5

Make cell entry in a range mandatory

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2018
    Location
    United Kingdom
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    12

    Make cell entry in a range mandatory

    I have a sheet that lists names, towns and whether a person has been checked.

    What I would like to do is when I enter something into cells A2 to A1000 then cells B2 to B1000 and E2 to E1000 become mandatory to have to enter something into.

    Could someone help me with this please.

    Thank you.
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,744

    Re: Make cell entry in a range mandatory

    I tested this code in the worksheet module:

    Option Explicit
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
       Dim R As Long
       
       If Cells(Target.Row, "A") <> "" And Target = "" And (Target.Column = 2 Or Target.Column = 5) Then
          ' user is about to fill in a required field, do nothing
       Else
          R = 2 ' first data row
          Do Until Cells(R, "A") = ""
             If Cells(R, "B") = "" Then
                MsgBox "You must provide " & Cells(1, "B") & " for " & Cells(R, "A") & " before continuing"
                Cells(R, "B").Select
                Exit Sub
             ElseIf Cells(R, "E") = "" Then
                MsgBox "You must provide " & Cells(1, "E") & " for " & Cells(R, "A") & " before continuing"
                Cells(R, "E").Select
                Exit Sub
             End If
          Loop
       End If
       
    End Sub
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    08-16-2018
    Location
    United Kingdom
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    12

    Re: Make cell entry in a range mandatory

    Thank you 6StringJazzer. That's the kind of solution I'm after however when I enter something into column E and go to select a cell in column A to enter the next name, Excel hangs (not responding). Any ideas why this might be please?

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,744

    Re: Make cell entry in a range mandatory

    Quote Originally Posted by h4a4r6r6 View Post
    Thank you 6StringJazzer. That's the kind of solution I'm after however when I enter something into column E and go to select a cell in column A to enter the next name, Excel hangs (not responding). Any ideas why this might be please?
    You may find JeteMc's solution a better fit, as it does not require macros. However, here is a fix for the problem in mine. I neglected to turn off events so that when the code makes a selection, it calls itself infinitely.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
       Dim R As Long
       
       Application.EnableEvents = False
       
       If Cells(Target.Row, "A") <> "" And Target = "" And (Target.Column = 2 Or Target.Column = 5) Then
          ' user is about to fill in a required field, do nothing
       Else
          R = 2 ' first data row
          Do Until Cells(R, "A") = ""
             If Cells(R, "B") = "" Then
                MsgBox "You must provide " & Cells(1, "B") & " for " & Cells(R, "A") & " before continuing"
                Cells(R, "B").Select
                Exit Sub
             ElseIf Cells(R, "E") = "" Then
                MsgBox "You must provide " & Cells(1, "E") & " for " & Cells(R, "A") & " before continuing"
                Cells(R, "E").Select
                Exit Sub
             End If
          Loop
       End If
       
       Application.EnableEvents = True
       
    End Sub

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,848

    Re: Make cell entry in a range mandatory

    If you are entering the names consecutively then the following formula based proposal may help.
    A helper column, which may be moved and/or hidden for aesthetic purposes, is populated using: =OR(A2="",AND(A2<>"",B2<>"",E2<>""))
    A formula is placed in data validation (custom) which reads: =F3=TRUE
    In the attached file data validation is applied to A3:A10 such that if a name is entered in A2 then B2 and E2 must be populated before a name can be entered in A3 etc.
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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. Make several cells mandatory if a cell in a range is filled out
    By steeveho in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-18-2013, 06:49 AM
  2. How can I make a cell mandatory?
    By eakkas@gmail.com in forum Excel General
    Replies: 3
    Last Post: 02-06-2006, 07:10 PM
  3. [SOLVED] How can I make a cell mandatory and only accept a Y or N?
    By Ron Rosenfeld in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 07:05 AM
  4. [SOLVED] How can I make a cell mandatory and only accept a Y or N?
    By Vicki in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  5. [SOLVED] How can I make a cell mandatory and only accept a Y or N?
    By Vicki in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  6. [SOLVED] How can I make a cell mandatory and only accept a Y or N?
    By Vicki in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  7. Making Cell Entry Mandatory
    By Sue T in forum Excel General
    Replies: 4
    Last Post: 08-17-2005, 11:06 AM

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