Microsoft Office Tutorials and References
In Depth Information
Data Validation
Using custom worksheet functions in data
validation formulas
Earlier in this chapter, I describe how to use custom VBA functions for conditional formatting
(see the “Using custom functions in conditional formatting formulas” section). For some reason,
Excel does not permit you to use a custom VBA function in a data validation formula. If you
attempt to do so, you get the following (erroneous) error message: A named range you
specified cannot be found.
To bypass this limitation, you can use the custom function in a cell formula and then specify a
data validation formula that refers to that cell.
If the formula that you enter contains a cell reference, that reference will be considered to be a
relative reference, based on the active cell in the selected range. This works exactly the same as
using a formula for conditional formatting. (See the “Creating formula-based rules” section,
earlier in this chapter.)
Using data validation formulas to accept only specific entries
Each of the following data validation examples uses a formula entered directly into the Formula
control in the Data Validation dialog box. You can set up these formulas to accept only text, a
certain value, nonduplicate entries, or text that begins with a specific letter.
All the examples in this section are available on the companion CD-ROM. The filename
is data validation examples.xlsx .
Accepting text only
Excel has a Data Validation option to limit the length of text entered into a cell, but it doesn’t
have an option to force text (rather than a number) into a cell. To force a cell or range to accept
only text (no values), use the following data validation formula:
=ISTEXT(A1)
This formula assumes that the active cell in the selected range is cell A1.
Accepting a larger value than the previous cell
The following data validation formula allows the user to enter a value only if it’s greater than the
value in the cell directly above it:
 
Search JabSto ::




Custom Search