?
Solved

Excel help to define a mandatory cell

Posted on 2007-03-29
5
Medium Priority
?
1,373 Views
Last Modified: 2008-01-09
I'm using Microsoft office 2003 and in excel I want to know if there is a way to make a field mandatory before moving to the next field kind of like it is done in Access.
0
Comment
Question by:centurian102
  • 4
5 Comments
 
LVL 17

Expert Comment

by:gtgloner
ID: 18816767
Paste this code in Sheet1 (or whatever sheet you want this to happen) of the VBA environment window. This will prompt the user to enter a value in Cell A1 if another cell is selected with A1 being empty:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 If Range("A1").Value = "" Then
  MsgBox ("You must enter a value for this cell")
 End If
End Sub
0
 
LVL 17

Expert Comment

by:gtgloner
ID: 18817022
Here is a slight improvement on my previous code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 If Range("A1").Value = "" Then
   Range("A1").Select
   MsgBox ("You must enter a value for Cell A1")
 End If
End Sub
0
 

Author Comment

by:centurian102
ID: 18817223
Can I choose this for multiple ranges? e.g. D9 through D15, I9 through I16, D20 through D26 and I20 through I26.
0
 
LVL 17

Expert Comment

by:gtgloner
ID: 18818403
Here is how to do it for your first range in a sheet. I haven't figured out how to get this to work for multiple ranges in the same sheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    For i = 9 To 15
        If Range("D" & i).Value = "" Then
         Range("D9:D15").Select
        End If
    Next i
End Sub
0
 
LVL 17

Accepted Solution

by:
gtgloner earned 375 total points
ID: 18818445
If a cell within this range is empty and the user tries to select a cell outside of this range, the range will be autoselected and remain so until the entire range is filled with some kind of character(s). To navigate through this range, the user has to click the Enter key until he gets to the cell that has nothing in it, then fill it with something. After all cells within this range have at least one character in it, the user will be able to navigate to some other cell(s) outside this range.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question