Data validation is a feature in Excel that allows you to restrict the type of data or the values that users can enter into a cell. For example, you can create a drop-down list of valid choices, or limit the input to numbers within a certain range. Data validation can help you prevent errors and ensure data consistency in your worksheets.
However, sometimes you may encounter a problem when creating a data validation list from a range of cells that contains blank cells. The blank cells will also appear in the drop-down list, which is not desirable. In this article, we will show you how to create a data validation fixed range but remove blanks in excel formula, using different methods.
Method 1: Using OFFSET Function
One way to create a data validation fixed range but remove blanks is to use the OFFSET function. The OFFSET function returns a reference to a range that is offset from a given cell or range by a certain number of rows and columns. You can use the OFFSET function to create a dynamic named range that expands or contracts based on the number of non-blank cells in the original range.
Here are the steps to use this method:
- Select the cell or cells where you want to apply the data validation list. In this example, we will use cell C2.
- Go to Data > Data Validation. In the Data Validation dialog box, select List from the Allow drop-down list.
- In the Source box, enter the formula
=OFFSET ($A$1,0,0,COUNTA ($A:$A),1)
, where$A$1
is the first cell of the range that contains the data for the list, and$A:$A
is the entire column that contains the data for the list. This formula will return a reference to a range that starts from cell A1 and has a height equal to the number of non-blank cells in column A, and a width of 1 column. You can adjust the formula according to your data location and size. - Click OK to apply the data validation list. You will see a drop-down arrow in the cell C2. Click on it and you will see the list of values without any blanks.
The advantage of this method is that it can handle blank cells in the middle of the range, as well as at the end of the range. However, it requires you to create a formula for each data validation list, which can be tedious and error-prone.
Method 2: Using FILTER Function
Another way to create a data validation fixed range but remove blanks is to use the FILTER function. The FILTER function returns a filtered range of data based on one or more criteria. You can use the FILTER function to create a new range of data that excludes the blank cells from the original range, and then use that new range as the source for the data validation list.
Here are the steps to use this method:
- Insert a new column next to the column that contains the data for the list. In this example, we will insert a new column B and name it List without Blanks.
- In the first cell of the new column, enter the formula
=FILTER (A:A,A:A<>"")
, where A:A is the column that contains the data for the list. This formula will return a range of data that filters out the blank cells from column A. You can adjust the formula according to your data location and size. - Select the cell or cells where you want to apply the data validation list. In this example, we will use cell C2.
- Go to Data > Data Validation. In the Data Validation dialog box, select List from the Allow drop-down list.
- In the Source box, enter the name of the new column, such as
=List without Blanks
. You can also use a named range or a cell reference instead of the column name. - Click OK to apply the data validation list. You will see a drop-down arrow in the cell C2. Click on it and you will see the list of values without any blanks.
The advantage of this method is that it is simpler and easier to use than the OFFSET function. However, it requires you to insert a new column for each data validation list, which can take up space and clutter your worksheet.
Method 3: Using Dynamic Array Formulas
A third way to create a data validation fixed range but remove blanks is to use dynamic array formulas. Dynamic array formulas are new features in Excel that allow you to enter a formula in one cell and return multiple results in a spill range. You can use dynamic array formulas to create a spill range of data that excludes the blank cells from the original range, and then use that spill range as the source for the data validation list.
Here are the steps to use this method:
- In an empty cell, enter the formula
=SORT (UNIQUE (FILTER (A:A,A:A<>"")))
, where A:A is the column that contains the data for the list. This formula will return a spill range of data that filters out the blank cells from column A, removes any duplicates, and sorts the values in ascending order. You can adjust the formula according to your data location and size. You will see a spill indicator in the bottom-right corner of the spill range, which shows the size and location of the spill range. - Select the cell or cells where you want to apply the data validation list. In this example, we will use cell C2.
- Go to Data > Data Validation. In the Data Validation dialog box, select List from the Allow drop-down list.
- In the Source box, enter the reference of the spill range, such as
=B2#
. The hash sign (#) indicates that you are referring to the entire spill range. You can also use a named range instead of the spill range reference. - Click OK to apply the data validation list. You will see a drop-down arrow in the cell C2. Click on it and you will see the list of values without any blanks.
The advantage of this method is that it does not require you to insert a new column or create a formula for each data validation list. However, it only works in Excel versions that support dynamic array formulas, such as Excel 365 or Excel 2021.
Scenario and Example
To illustrate how these methods work, let us consider a scenario where we have a list of products in column A, and we want to create a data validation list in cell C2 that allows us to select a product from the list, but without any blanks. The list of products contains some blank cells, as shown below:
![Image of list of products with blanks]
Using the methods described above, we can create a data validation fixed range but remove blanks in excel formula, and get the following result:
![Image of data validation list without blanks]
As you can see, the data validation list in cell C2 only shows the products that are not blank, and excludes the blank cells from the list.