Solved

Excel help to define a mandatory cell

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now