Solved

Excel help to define a mandatory cell

Posted on 2007-03-29
5
1,360 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 125 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

810 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