Sub topic 2
Create a drop-down from a typed list of items
A drop-down built from typed items is the simplest validated input in Google Sheets. You type the allowed values into the validation rule, and the cell then accepts only those values. This chapter covers the rule, how it behaves, and the edge cases that cause trouble later.
This chapter assumes you can select cells and ranges, enter values and simple formulas, and read references such as A2 and $A$2. It uses no formulas. The Apps Script section at the end is optional.
What a typed-item drop-down is
A typed-item drop-down is a data validation rule whose criteria is Drop-down. The list of allowed values is stored inside the rule itself, not in cells on a sheet. That has two consequences:
- The list is easy to set up. You do not need a helper range or a second sheet.
- The list is hard to share. If the same list is needed in several places, you must edit each rule separately.
The next chapter covers drop-downs driven by a cell range. Those fix the second problem. Use typed items when the list is short, stable, and used in one place, such as Not started, In progress, Done.
Create the rule
- Select the cells that should show the drop-down, for example
C2:C100. - Open Data > Data validation, or right-click a cell and choose Dropdown from the menu. The sidebar opens.
- Choose Add rule.
- Check Apply to range. It should show the range you selected. You can edit it by hand, or add more ranges.
- Under Criteria, choose Drop-down.
- Type the first item in the first option box. Choose Add another item and type the next one. Repeat until the list is complete.
- Choose Done.
Each cell in the range now shows a small arrow, or a chip, depending on the display style you chose. Selecting the cell opens the list. Clicking an item enters it.
Item colors and order
Each item has a color swatch to its left. The color is optional. It fills the chip, or the cell background, when that item is selected. Colors are useful for status columns because a column of Done in green and In progress in yellow can be scanned at a glance.
Items appear in the drop-down in the order you list them. Use the drag handle on the left of an item to reorder. Use the X on the right to delete one. Order matters for usability. Put the most common choice first, or use the natural sequence of a workflow.
Decide what happens with invalid input
Under Advanced options, the If the data is invalid setting has two choices:
| Setting | What happens when someone types a value not in the list |
|---|---|
| Show a warning | The entry is accepted. The cell gets a red marker in its corner, and hovering over it shows a message. |
| Reject the input | A message appears and the value is not stored. The cell keeps its previous content. |
Choose Reject the input for a column that downstream formulas depend on, such as a status that feeds a count. Choose Show a warning when the list is a guide and occasional exceptions are legitimate. The next chapters cover this choice in more depth. For now, remember that it applies to typing and to clicking items alike, but only typing can produce an invalid value in the first place.
The same Advanced options area lets you set Show validation help text. Help text appears when someone selects the cell, so it is a good place to say what the list means. A later chapter covers it.
Choose a display style
Under Advanced options, Display style has three settings:
- Chip shows the selected item as a rounded label with its color. It is the default in recent versions.
- Arrow shows plain text with a small arrow in the cell.
- Plain text hides the arrow. The list still opens when you double-click the cell or press Enter on it.
Display style changes appearance only. It does not change which values are accepted.
What the cell actually contains
When someone picks an item, Sheets enters it as if the user had typed it. This detail causes most surprises with typed lists.
- An item such as
1or2is stored as a number, so formulas such asSUMtreat it as one. - An item that looks like a date, such as
3/4, may be converted to a date value. Sheets interprets text the way it does for any typed entry. - An item with a leading apostrophe is stored as text, but the apostrophe itself is not shown.
- Leading and trailing spaces can be kept in an item, which makes it look the same as another item while being a different value. Avoid them.
If you need numbers such as 1, 2, 3, a typed list works well. If you need labels that resemble numbers or dates, test a selected value with =ISTEXT(C2) or =ISNUMBER(C2) before relying on it.
Edit the list later
To change a rule, select any cell it covers, open Data > Data validation, and click the rule in the sidebar. You can add, rename, reorder, or delete items.
Two behaviors matter when you edit a list:
- Renaming an item does not rewrite the cells that already hold the old value. If you change
DonetoComplete, existing cells still sayDone. They are now values that are not in the list, so they are flagged as invalid. Fix them with Find and replace (Edit > Find and replace), or with a formula and paste-as-values. - Deleting an item has the same effect. Cells that hold it keep the value and are flagged.
Plan the wording before filling hundreds of rows. Changing the list afterward costs a cleanup step.
Clear a rule
To remove validation, select the cells, open Data > Data validation, and choose Remove rule in the sidebar. You can also select the cells and choose Delete on a rule listed there. The values in the cells stay. Only the restriction goes away.
Note that pressing Delete on the cells themselves clears the values, not the rule. Clearing a cell is always allowed, even when blank is not in the list.
Create the same rule with Apps Script
You can also build the rule in code, which is useful when you must apply identical rules to many sheets. The example below applies a three-item list to C2:C100, rejects other values, and shows help text.
function addStatusDropdown() {
const sheet = SpreadsheetApp.getActiveSheet();
const rule = SpreadsheetApp.newDataValidation()
.requireValueInList(['Not started', 'In progress', 'Done'], true)
.setAllowInvalid(false)
.setHelpText('Pick a status from the list.')
.build();
sheet.getRange('C2:C100').setDataValidation(rule);
}The pieces map to the sidebar like this:
| Code | Sidebar equivalent |
|---|---|
| `requireValueInList([...], true)` | Criteria: Drop-down, with the typed items. The `true` shows the arrow in the cell. |
| `setAllowInvalid(false)` | If the data is invalid: Reject the input. Use `true` for a warning. |
| `setHelpText(...)` | Show validation help text. |
| `setDataValidation(rule)` | Apply to range. |
To check what a cell holds, read the rule back:
function inspectStatusRule() {
const rule = SpreadsheetApp.getActiveSheet().getRange('C2').getDataValidation();
if (!rule) {
Logger.log('No validation rule on C2.');
return;
}
Logger.log(rule.getCriteriaType());
Logger.log(rule.getCriteriaValues());
Logger.log('Allows invalid input: ' + rule.getAllowInvalid());
}For a typed list, the criteria type is VALUE_IN_LIST. Run the function and open Execution log to see the result. A later chapter returns to Apps Script in more detail.
Common errors
- The drop-down arrow is missing. Display style may be set to Plain text, or the rule does not cover that cell. Click the cell and check which rule the sidebar shows.
- A value was accepted that is not in the list. The rule is set to Show a warning, or the value was pasted. Paste can overwrite validation in some cases, and a later chapter covers it.
- Old values are flagged after editing the list. The cells keep their old text. Replace the values or restore the item.
- A list item with a comma splits in two. Items are entered one per box in the sidebar, so a comma is part of the item. This problem only arises if you build lists from text elsewhere, such as pasted comma-separated text. Enter one item per box.
- Two nearly identical items.
DoneandDone(with a trailing space) are different values. Counting formulas treat them separately.
When to use typed items
Typed items are the right choice when all of these are true:
- The list has a handful of items.
- The items rarely change.
- The list is used in one range, or a few ranges that you manage together.
Switch to a range-driven drop-down when the list is long, when other people maintain it, or when several sheets share it. Then one edit to the list updates every rule that points at it.
Exercise
A tracker has a status column with a typed drop-down of Open, Closed, and Pending, set to reject invalid input. Your manager asks you to rename Pending to On hold. You edit the item in the rule, and then notice that rows which previously said Pending still show that text with a red marker. Why did this happen, and what is the quickest way to fix it?
Show answer
Editing a rule changes only which values are allowed. It does not rewrite the cell contents. The rows still hold the text Pending, which is no longer in the list, so Sheets flags them. The quickest fix is Edit > Find and replace. Search for Pending, replace with On hold, set the search to the status column's range, and choose Replace all. The markers disappear because the values now match the list.
Exercise
Write the Apps Script call chain that applies a drop-down of Low, Medium, and High to D2:D50, and that accepts other typed values but marks them with a warning instead of rejecting them. Which method controls this behavior, and what argument do you pass?
Show answer
Use SpreadsheetApp.newDataValidation().requireValueInList(['Low', 'Medium', 'High'], true).setAllowInvalid(true).build(), then call sheet.getRange('D2:D50').setDataValidation(rule). The method setAllowInvalid controls the behavior. Passing true shows a warning, and passing false rejects the input.