Solved

Excel help to define a mandatory cell

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
excel pivot question 4 42
macro for each dropdown 15 46
Excel Copy Macro down foe each row 4 21
CUT & PASTE VALUES IN EXCEL USING MACRO -- SPECIFIC CELLS 27 24
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

863 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

26 Experts available now in Live!

Get 1:1 Help Now