Counting is an integral part of data analysis, whether you are tallying the head count of a department in your organization or the number of units that were sold quarter-by-quarter. Excel provides multiple techniques that you can use to count cells, rows, or columns of data. To help you make the best choice, this article provides a comprehensive summary of methods, a downloadable workbook with interactive examples, and links to related topics for further understanding.
Download our examples
You can download an example workbook that gives examples to supplement the information in this article. Most sections in this article will refer to the appropriate worksheet within the example workbook that provides examples and more information.
Download examples to count values in a spreadsheet
In this article
-
Simple counting
-
Use AutoSum
-
Add a Subtotal row
-
Count cells in a list or Excel table column by using the SUBTOTAL function
-
-
Counting based on one or more conditions
-
Video: Use the COUNT, COUNTIF, and COUNTA functions
-
Count cells in a range by using the COUNT function
-
Count cells in a range based on a single condition by using the COUNTIF function
-
Count cells in a column based on single or multiple conditions by using the DCOUNT function
-
Count cells in a range based on multiple conditions by using the COUNTIFS function
-
Count based on criteria by using the COUNT and IF functions together
-
Count how often multiple text or number values occur by using the SUM and IF functions together
-
Count cells in a column or row in a PivotTable
-
-
Counting when your data contains blank values
-
Count nonblank cells in a range by using the COUNTA function
-
Count nonblank cells in a list with specific conditions by using the DCOUNTA function
-
Count blank cells in a contiguous range by using the COUNTBLANK function
-
Count blank cells in a non-contiguous range by using a combination of SUM and IF functions
-
-
Counting unique occurrences of values
-
Count the number of unique values in a list column by using Advanced Filter
-
Count the number of unique values in a range that meet one or more conditions by using IF, SUM, FREQUENCY, MATCH, and LEN functions
-
-
Special cases (count all cells, count words)
-
Count the total number of cells in a range by using ROWS and COLUMNS functions
-
Count words in a range by using a combination of SUM, IF, LEN, TRIM, and SUBSTITUTE functions
-
-
Displaying calculations and counts on the status bar
Simple counting
You can count the number of values in a range or table by using a simple formula, clicking a button, or by using a worksheet function.
Excel can also display the count of the number of selected cells on the Excel status bar. See the video demo that follows for a quick look at using the status bar. Also, see the section Displaying calculations and counts on the status bar for more information. You can refer to the values shown on the status bar when you want a quick glance at your data and don’t have time to enter formulas.
Video: Count cells by using the Excel status bar
Watch the following video to learn how to view count on the status bar.
Use AutoSum
Use AutoSum by selecting a range of cells that contains at least one numeric value. Then on the Formulas tab, click AutoSum > Count Numbers.
Excel returns the count of the numeric values in the range in a cell adjacent to the range you selected. Generally, this result is displayed in a cell to the right for a horizontal range or in a cell below for a vertical range.
Top of Page
Add a Subtotal row
You can add a subtotal row to your Excel data. Click anywhere inside your data, and then click Data > Subtotal.
Note: The Subtotal option will only work on normal Excel data, and not Excel tables, PivotTables, or PivotCharts.
Also, refer to the following articles:
-
Outline (group) data in a worksheet
-
Insert subtotals in a list of data in a worksheet
Top of Page
Count cells in a list or Excel table column by using the SUBTOTAL function
Use the SUBTOTAL function to count the number of values in an Excel table or range of cells. If the table or range contains hidden cells, you can use SUBTOTAL to include or exclude those hidden cells, and this is the biggest difference between SUM and SUBTOTAL functions.
The SUBTOTAL syntax goes like this:
SUBTOTAL(function_num,ref1,[ref2],…)
To include hidden values in your range, you should set the function_num argument to 2.
To exclude hidden values in your range, set the function_num argument to 102.
Top of Page
Counting based on one or more conditions
You can count the number of cells in a range that meet conditions (also known as criteria) that you specify by using a number of worksheet functions.
Video: Use the COUNT, COUNTIF, and COUNTA functions
Watch the following video to see how to use the COUNT function and how to use the COUNTIF and COUNTA functions to count only the cells that meet conditions you specify.
Top of Page
Count cells in a range by using the COUNT function
Use the COUNT function in a formula to count the number of numeric values in a range.
In the above example, A2, A3, and A6 are the only cells that contains numeric values in the range, hence the output is 3.
Note: A7 is a time value, but it contains text (a.m.), hence COUNT does not consider it a numerical value. If you were to remove a.m. from the cell, COUNT will consider A7 as a numerical value, and change the output to 4.
Top of Page
Count cells in a range based on a single condition by using the COUNTIF function
Use the COUNTIF function function to count how many times a particular value appears in a range of cells.
Top of Page
Count cells in a column based on single or multiple conditions by using the DCOUNT function
DCOUNT function counts the cells that contain numbers in a field (column) of records in a list or database that match conditions that you specify.
In the following example, you want to find the count of the months including or later than March 2016 that had more than 400 units sold. The first table in the worksheet, from A1 to B7, contains the sales data.
DCOUNT uses conditions to determine where the values should be returned from. Conditions are typically entered in cells in the worksheet itself, and you then refer to these cells in the criteria argument. In this example, cells A10 and B10 contain two conditions—one that specifies that the return value must be greater than 400, and the other that specifies that the ending month should be equal to or greater than March 31st, 2016.
You should use the following syntax:
=DCOUNT(A1:B7,»Month ending»,A9:B10)
DCOUNT checks the data in the range A1 through B7, applies the conditions specified in A10 and B10, and returns 2, the total number of rows that satisfy both conditions (rows 5 and 7).
Top of Page
Count cells in a range based on multiple conditions by using the COUNTIFS function
The COUNTIFS function is similar to the COUNTIF function with one important exception: COUNTIFS lets you apply criteria to cells across multiple ranges and counts the number of times all criteria are met. You can use up to 127 range/criteria pairs with COUNTIFS.
The syntax for COUNTIFS is:
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2],…)
See the following example:
Top of Page
Count based on criteria by using the COUNT and IF functions together
Let’s say you need to determine how many salespeople sold a particular item in a certain region or you want to know how many sales over a certain value were made by a particular salesperson. You can use the IF and COUNT functions together; that is, you first use the IF function to test a condition and then, only if the result of the IF function is True, you use the COUNT function to count cells.
Notes:
-
The formulas in this example must be entered as array formulas. If you have opened this workbook in Excel for Windows or Excel 2016 for Mac and want to change the formula or create a similar formula, press F2, and then press Ctrl+Shift+Enter to make the formula return the results you expect. In earlier versions of Excel for Mac, use +Shift+Enter.
-
For the example formulas to work, the second argument for the IF function must be a number.
Top of Page
Count how often multiple text or number values occur by using the SUM and IF functions together
In the examples that follow, we use the IF and SUM functions together. The IF function first tests the values in some cells and then, if the result of the test is True, SUM totals those values that pass the test.
Example 1
The above function says if C2:C7 contains the values Buchanan and Dodsworth, then the SUM function should display the sum of records where the condition is met. The formula finds three records for Buchanan and one for Dodsworth in the given range, and displays 4.
Example 2
The above function says if D2:D7 contains values lesser than $9000 or greater than $19,000, then SUM should display the sum of all those records where the condition is met. The formula finds two records D3 and D5 with values lesser than $9000, and then D4 and D6 with values greater than $19,000, and displays 4.
Example 3
The above function says if D2:D7 has invoices for Buchanan for less than $9000, then SUM should display the sum of records where the condition is met. The formula finds that C6 meets the condition, and displays 1.
Important: The formulas in this example must be entered as array formulas. That means you press F2 and then press Ctrl+Shift+Enter. In earlier versions of Excel for Mac use +Shift+Enter.
See the following Knowledge Base articles for additional tips:
-
XL: Using SUM(IF()) As an Array Function Instead of COUNTIF() with AND
-
XL: How to Count the Occurrences of a Number or Text in a Range
Top of Page
Count cells in a column or row in a PivotTable
A PivotTable summarizes your data and helps you analyze and drill down into your data by letting you choose the categories on which you want to view your data.
You can quickly create a PivotTable by selecting a cell in a range of data or Excel table and then, on the Insert tab, in the Tables group, clicking PivotTable.
Let’s look at a sample scenario of a Sales spreadsheet, where you can count how many sales values are there for Golf and Tennis for specific quarters.
Note: For an interactive experience, you can run these steps on the sample data provided in the PivotTable sheet in the downloadable workbook.
-
Enter the following data in an Excel spreadsheet.
-
Select A2:C8
-
Click Insert > PivotTable.
-
In the Create PivotTable dialog box, click Select a table or range, then click New Worksheet, and then click OK.
An empty PivotTable is created in a new sheet.
-
In the PivotTable Fields pane, do the following:
-
Drag Sport to the Rows area.
-
Drag Quarter to the Columns area.
-
Drag Sales to the Values area.
-
Repeat step c.
The field name displays as SumofSales2 in both the PivotTable and the Values area.
At this point, the PivotTable Fields pane looks like this:
-
In the Values area, click the dropdown next to SumofSales2 and select Value Field Settings.
-
In the Value Field Settings dialog box, do the following:
-
In the Summarize value field by section, select Count.
-
In the Custom Name field, modify the name to Count.
-
Click OK.
-
The PivotTable displays the count of records for Golf and Tennis in Quarter 3 and Quarter 4, along with the sales figures.
-
Top of Page
Counting when your data contains blank values
You can count cells that either contain data or are blank by using worksheet functions.
Count nonblank cells in a range by using the COUNTA function
Use the COUNTA function function to count only cells in a range that contain values.
When you count cells, sometimes you want to ignore any blank cells because only cells with values are meaningful to you. For example, you want to count the total number of salespeople who made a sale (column D).
COUNTA ignores the blank values in D3, D4, D8, and D11, and counts only the cells containing values in column D. The function finds six cells in column D containing values and displays 6 as the output.
Top of Page
Count nonblank cells in a list with specific conditions by using the DCOUNTA function
Use the DCOUNTA function to count nonblank cells in a column of records in a list or database that match conditions that you specify.
The following example uses the DCOUNTA function to count the number of records in the database that is contained in the range A1:B7 that meet the conditions specified in the criteria range A9:B10. Those conditions are that the Product ID value must be greater than or equal to 2000 and the Ratings value must be greater than or equal to 50.
DCOUNTA finds two rows that meet the conditions- rows 2 and 4, and displays the value 2 as the output.
Top of Page
Count blank cells in a contiguous range by using the COUNTBLANK function
Use the COUNTBLANK function function to return the number of blank cells in a contiguous range (cells are contiguous if they are all connected in an unbroken sequence). If a cell contains a formula that returns empty text («»), that cell is counted.
When you count cells, there may be times when you want to include blank cells because they are meaningful to you. In the following example of a grocery sales spreadsheet. suppose you want to find out how many cells don’t have the sales figures mentioned.
Note: The COUNTBLANK worksheet function provides the most convenient method for determining the number of blank cells in a range, but it doesn’t work very well when the cells of interest are in a closed workbook or when they do not form a contiguous range. The Knowledge Base article XL: When to Use SUM(IF()) instead of CountBlank() shows you how to use a SUM(IF()) array formula in those cases.
Top of Page
Count blank cells in a non-contiguous range by using a combination of SUM and IF functions
Use a combination of the SUM function and the IF function. In general, you do this by using the IF function in an array formula to determine whether each referenced cell contains a value, and then summing the number of FALSE values returned by the formula.
See a few examples of SUM and IF function combinations in an earlier section Count how often multiple text or number values occur by using the SUM and IF functions together in this topic.
Top of Page
Counting unique occurrences of values
You can count unique values in a range by using a PivotTable, COUNTIF function, SUM and IF functions together, or the Advanced Filter dialog box.
Count the number of unique values in a list column by using Advanced Filter
Use the Advanced Filter dialog box to find the unique values in a column of data. You can either filter the values in place or you can extract and paste them to a new location. Then you can use the ROWS function to count the number of items in the new range.
To use Advanced Filter, click the Data tab, and in the Sort & Filter group, click Advanced.
The following figure shows how you use the Advanced Filter to copy only the unique records to a new location on the worksheet.
In the following figure, column E contains the values that were copied from the range in column D.
Notes:
-
If you filter your data in place, values are not deleted from your worksheet — one or more rows might be hidden. Click Clear in the Sort & Filter group on the Data tab to display those values again.
-
If you only want to see the number of unique values at a quick glance, select the data after you have used the Advanced Filter (either the filtered or the copied data) and then look at the status bar. The Count value on the status bar should equal the number of unique values.
For more information, see Filter by using advanced criteria
Top of Page
Count the number of unique values in a range that meet one or more conditions by using IF, SUM, FREQUENCY, MATCH, and LEN functions
Use various combinations of the IF, SUM, FREQUENCY, MATCH, and LEN functions.
For more information and examples, see the section «Count the number of unique values by using functions» in the article Count unique values among duplicates.
Top of Page
Special cases (count all cells, count words)
You can count the number of cells or the number of words in a range by using various combinations of worksheet functions.
Count the total number of cells in a range by using ROWS and COLUMNS functions
Suppose you want to determine the size of a large worksheet to decide whether to use manual or automatic calculation in your workbook. To count all the cells in a range, use a formula that multiplies the return values using the ROWS and COLUMNS functions. See the following image for an example:
Top of Page
Count words in a range by using a combination of SUM, IF, LEN, TRIM, and SUBSTITUTE functions
You can use a combination of the SUM, IF, LEN, TRIM, and SUBSTITUTE functions in an array formula. The following example shows the result of using a nested formula to find the number of words in a range of 7 cells (3 of which are empty). Some of the cells contain leading or trailing spaces — the TRIM and SUBSTITUTE functions remove these extra spaces before any counting occurs. See the following example:
Now, for the above formula to work correctly, you have to make this an array formula, otherwise the formula returns the #VALUE! error. To do that, click on the cell that has the formula, and then in the Formula bar, press Ctrl + Shift + Enter. Excel adds a curly bracket at the beginning and the end of the formula, thus making it an array formula.
For more information on array formulas, see Overview of formulas in Excel and Create an array formula.
Top of Page
Displaying calculations and counts on the status bar
When one or more cells are selected, information about the data in those cells is displayed on the Excel status bar. For example, if four cells on your worksheet are selected, and they contain the values 2, 3, a text string (such as «cloud»), and 4, all of the following values can be displayed on the status bar at the same time: Average, Count, Numerical Count, Min, Max, and Sum. Right-click the status bar to show or hide any or all of these values. These values are shown in the illustration that follows.
Top of Page
Need more help?
You can always ask an expert in the Excel Tech Community or get support in the Answers community.
Watch Video – 7 Quick and Easy Ways to Number Rows in Excel
When working with Excel, there are some small tasks that need to be done quite often. Knowing the ‘right way’ can save you a great deal of time.
One such simple (yet often needed) task is to number the rows of a dataset in Excel (also called the serial numbers in a dataset).
Now if you’re thinking that one of the ways is to simply enter these serial number manually, well – you’re right!
But that’s not the best way to do it.
Imagine having hundreds or thousands of rows for which you need to enter the row number. It would be tedious – and completely unnecessary.
There are many ways to number rows in Excel, and in this tutorial, I am going to share some of the ways that I recommend and often use.
Of course, there would be more, and I will be waiting – with a coffee – in the comments area to hear from you about it.
How to Number Rows in Excel
The best way to number the rows in Excel would depend on the kind of data set that you have.
For example, you may have a continuous data set that starts from row 1, or a dataset that start from a different row. Or, you might have a dataset that has a few blank rows in it, and you only want to number the rows that are filled.
You can choose any one of the methods that work based on your dataset.
1] Using Fill Handle
Fill handle identifies a pattern from a few filled cells and can easily be used to quickly fill the entire column.
Suppose you have a dataset as shown below:
Here are the steps to quickly number the rows using the fill handle:
Note that Fill Handle automatically identifies the pattern and fill the remaining cells with that pattern. In this case, the pattern was that the numbers were getting incrementing by 1.
In case you have a blank row in the dataset, fill handle would only work till the last contiguous non-blank row.
Also, note that in case you don’t have data in the adjacent column, double-clicking the fill handle would not work. You can, however, place the cursor on the fill handle, hold the right mouse key and drag down. It will fill the cells covered by the cursor dragging.
2] Using Fill Series
While Fill Handle is a quick way to number rows in Excel, Fill Series gives you a lot more control over how the numbers are entered.
Suppose you have a dataset as shown below:
Here are the steps to use Fill Series to number rows in Excel:
This will instantly number the rows from 1 to 26.
Using ‘Fill Series’ can be useful when you’re starting by entering the row numbers. Unlike Fill Handle, it doesn’t require the adjacent columns to be filled already.
Even if you have nothing on the worksheet, Fill Series would still work.
Note: In case you have blank rows in the middle of the dataset, Fill Series would still fill the number for that row.
3] Using the ROW Function
You can also use Excel functions to number the rows in Excel.
In the Fill Handle and Fill Series methods above, the serial number inserted is a static value. This means that if you move the row (or cut and paste it somewhere else in the dataset), the row numbering will not change accordingly.
This shortcoming can be tackled using formulas in Excel.
You can use the ROW function to get the row numbering in Excel.
To get the row numbering using the ROW function, enter the following formula in the first cell and copy for all the other cells:
=ROW()-1
The ROW() function gives the row number of the current row. So I have subtracted 1 from it as I started from the second row onwards. If your data starts from the 5th row, you need to use the formula =ROW()-4.
The best part about using the ROW function is that it will not screw up the numberings if you delete a row in your dataset.
Since the ROW function is not referencing any cell, it will automatically (or should I say AutoMagically) adjust to give you the correct row number. Something as shown below:
Note that as soon as I delete a row, the row numbers automatically update.
Again, this would not take into account any blank records in the dataset. In case you have blank rows, it will still show the row number.
You can use the following formula to hide the row number for blank rows, but it would still not adjust the row numbers (such that the next row number is assigned to the next filled row).
IF(ISBLANK(B2),"",ROW()-1)
4] Using the COUNTA Function
If you want to number rows in a way that only the ones that are filled get a serial number, then this method is the way to go.
It uses the COUNTA function that counts the number of cells in a range that are not empty.
Suppose you have a dataset as shown below:
Note that there are blank rows in the above-shown dataset.
Here is the formula that will number the rows without numbering the blank rows.
=IF(ISBLANK(B2),"",COUNTA($B$2:B2))
The IF function checks whether the adjacent cell in column B is empty or not. If it’s empty, it returns a blank, but if it’s not, it returns the count of all the filled cells till that cell.
5] Using SUBTOTAL For Filtered Data
Sometimes, you may have a huge dataset, where you want to filter the data and then copy and paste the filtered data into a separate sheet.
If you use any of the methods shown above so far, you will notice that the row numbers remain the same. This means that when you copy the filtered data, you will have to update the row numbering.
In such cases, the SUBTOTAL function can automatically update the row numbers. Even when you filter the data set, the row numbers will remain intact.
Let me show you exactly how it works with an example.
Suppose you have a dataset as shown below:
If I filter this data based on Product A sales, you will get something as shown below:
Note that the serial numbers in Column A are also filtered. So now, you only see the numbers for the rows that are visible.
While this is the expected behavior, in case you want to get a serial row numbering – so that you can simply copy and paste this data somewhere else – you can use the SUBTOTAL function.
Here is the SUBTOTAL function that will make sure that even the filtered data has continuous row numbering.
=SUBTOTAL(3,$B$2:B2)
The 3 in the SUBTOTAL function specifies using the COUNTA function. The second argument is the range on which COUNTA function is applied.
The benefit of the SUBTOTAL function is that it dynamically updates when you filter the data (as shown below):
Note that even when the data is filtered, the row numbering update and remains continuous.
6] Creating an Excel Table
Excel Table is a great tool that you must use when working with tabular data. It makes managing and using data a lot easier.
This is also my favorite method among all the techniques shown in this tutorial.
Let me first show you the right way to number the rows using an Excel Table:
Note that in the formula above, I have used Table2, as that is the name of my Excel table. You can replace Table2 with the name of the table you have.
There are some added benefits of using an Excel Table while numbering rows in Excel:
- Since Excel Table automatically inserts the formula in the entire column, it works when you insert a new row in the Table. This means that when you insert/delete rows in an Excel Table, the row numbering would automatically update (as shown below).
- If you add more rows to the data, Excel Table would automatically expand to include this data as a part of the table. And since the formulas automatically update in the calculated columns, it would insert the row number for the newly inserted row (as shown below).
7] Adding 1 to the Previous Row Number
This is a simple method that works.
The idea is to add 1 to the previous row number (the number in the cell above). This will make sure that subsequent rows get a number that is incremented by 1.
Suppose you have a dataset as shown below:
Here are the steps to enter row numbers using this method:
- In the cell in the first row, enter 1 manually. In this case, it’s in cell A2.
- In cell A3, enter the formula, =A2+1
- Copy and paste the formula for all the cells in the column.
The above steps would enter serial numbers in all the cells in the column. In case there are any blank rows, this would still insert the row number for it.
Also note that in case you insert a new row, the row number would not update. In case you delete a row, all the cells below the deleted row would show a reference error.
These are some quick ways you can use to insert serial numbers in tabular data in Excel.
In case you are using any other method, do share it with me in the comments section.
You May Also Like the Following Excel Tutorials:
- Delete Blank Rows in Excel (with and without VBA).
- How to Insert Multiple Rows in Excel (4 Methods).
- How to Split Multiple Lines in a Cell into a Separate Cells / Columns.
- 7 Amazing Things Excel Text to Columns Can Do For You.
- Highlight EVERY Other ROW in Excel.
- How to Compare Two Columns in Excel.
- Insert New Columns in Excel
Numbering cells is a task often you’ll often perform in Excel. But writing the number manually in each cell takes a lot of time.
Fortunately, there are methods that help you add numbers automatically. And in this article, I’ll show you two methods of doing so: the first is a simple method, and the second lets you have dynamically numbered cells. So let’s get started.
How to Auto-Number Cells with a Regular Pattern
For this method, you set your starting number in one cell and the next number in the series in the next cell.
Once you have two adjacent cells filled with your two starting numbers, you can select those two cells, click on the handle in the bottom right corner of the green outline, and drag to select all the cells that you want to follow your pattern.
A useful tooltip appears near the bottom right corner of the green outline to show what the last number in the series would be if you released at that point.
So, if you want to start with the number 5 and increment by 3 until 38, you would write 5 in your first cell, and 8 in the next cell. You would then select the cells containing the 5 and the 8, click on the handle, and drag to select the other cells until you see 38
appear in the tooltip. Then you can release, and the numbers will be filled in automatically.
The numbers can also be formatted in descending order: if you start with 7 and then enter 5, the pattern will continue with 3, 1, -1, and so on.
You can also do the same with rows instead of columns. Fill in two consecutive cells in a row with the start of your pattern, then select them and drag the outline horizontally across those cells that you want to continue that pattern. It’ll automatically fill in those numbers.
You can also do the same going upward – fill two cells, select them, click the handle and drag upward to fill the cells above your two starting cells.
Note: this will always add numbers that are evenly spaced in the pattern you’ve started. It won’t work with other kinds of number progressions.
How to Auto-Number Cells Using the ROW() Function
If you have data that can be sorted in different ways (say, a list of names — alphabetically, etc), it’s annoying if the numbering of your lines gets scrambled when you’re sorting other data.
To avoid that, you can dynamically number your rows using the ROW()
function.
In the cell where you want the numbering to start, write =ROW(A1)
. This will produce the number 1 in the cell.
Select the cell and drag the outline from the handle in the corner to populate the same formula in the rest of the cells (or, if you are adding the line numbers near a block of data already present, you can just double-click on the handle on the corner of the selection).
=ROW(A1)
in your first cell, 2) It will appear as the number1
, 3) Click and drag or double-click to fill all other cells. 4) Now if you sort the data, the line numbers will stay in order.
If you want to have a different regular pattern, you can use a bit of math: to have numbers spaced by 2, you can write =ROW(A1) * 2
in the first cell, and then proceed with the same steps as above. This will produce the numbers 2, 4, 6…and so on.
If you want to change the starting point of the pattern – to maybe have only odd numbers, for example – you can subtract one: =ROW(A1) * 2 - 1
, this will produce the numbers 1, 3, 5, 7…
As a general formula, to get any pattern you can write =ROW(A1) * a + b
. a
is used to determine the step, and b
(it can be either a positive or negative number) is used to change the starting point of the pattern.
If you want to number your columns, you can use the COLUMN()
function in the same way as the ROW()
. Just fill in your first cell with =COLUMN(A1)
, select the cell, then expand the selection to the rest of the cells you want your numbers to be in.
Note: if you add or delete rows, you will need to set the auto-numbering again by selecting the first cell and dragging or double-clicking again to restore the pattern.
Conclusion
Writing numbers in cells is a task often performed in Excel, and here we have seen two simple methods that let us save time. The first method just involves writing numbers in two cells, and then a couple of clicks. And the other just requires writing a formula in one cell, and then a couple of clicks.
There are a few other methods for numbering cells in Excel, but these are the most straightforward.
Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started
We can number cells in Excel by using the fill handle, or we can automatically number rows by using the ROW function. This article assists all levels of Excel users on how to number cells.
Figure 1. Final result: How to number cells
Numbering rows
- Select the cell where we want to insert the first row number, say B3, and enter “1”
Figure 2. Entering the first row number
- Type another value in the next cell to establish a pattern. Enter “2” in cell B4.
Figure 3. Entering the second row number
- Select cells B3 and B4. The fill handle will appear at the bottom right corner of the selected cells.
Figure 4. Selecting the first two cells to establish pattern
- Click, hold and drag the fill handle down until the last cell we want to fill.
Figure 5. Output: Numbering rows
We have now filled the column for row with numbers 1 to 10. However, we have also copied the formatting of cells B3 and B4 and it has distorted the format of our table.
Fill without formatting
In order to fill the row numbers without formatting, we have to drag down the fill handle using the riight-click button of the mouse. When we release the mouse, options will be provided and we can choose Fill without Formatting to achieve the desired result.
Figure 6. Fill without Formatting option
Finally, we have filled all rows with a row number without distorting the current format of cells.
Figure 7. Output: Numbering without formatting
Auto numbering
Next, let us learn how to automatically number rows by using the ROW function and an offset value.
- Select the first cell where we want to insert the first row number, say B3
- Enter the sequence formula using the ROW function
= ROW()-2
Figure 8. Entering the sequence formula
The ROW function returns the row number of the cell in the worksheet. We have selected cell B3 so the ROW function returns the value 3. Therefore, we need to subtract 2 from the ROW function in order to obtain row number “1” for the first row.
The formula for sequential numbering is therefore given as:
=ROW()-[offset]
In this case, the offset is the number 2.
- Click the fill handle of cell B3 using the right-click button, and drag down to cell B12.
- Choose Fill without Formatting to copy only the formula.
Figure 9. Output: Auto numbering using ROW function
Note that the formula in cell B12 is the same as the formula in cell B3. Finally, we have learned how to number cells by using sequential row numbers.
Instant Connection to an Excel Expert
Most of the time, the problem you will need to solve will be more complex than a simple application of a formula or function. If you want to save hours of research and frustration, try our live Excelchat service! Our Excel Experts are available 24/7 to answer any Excel question you may have. We guarantee a connection within 30 seconds and a customized solution within 20 minutes.
This post is going to show you all the ways you can convert text to numbers in Microsoft Excel.
An issue that comes up quite often in Excel is numbers that have been entered or formatted as text values.
This can cause many headaches when trying to troubleshoot why a formula like a SUM is not giving the correct answer.
Even though the data looks like a number, it can actually be a text value and will be ignored from any numerical calculations like a sum.
In this post, I will show you how you can identify such numbers which are stored as text values, and 7 ways you can use to convert the text into a proper number value.
How to Indentify Numbers Entered as Text
How can you tell if your number data has been entered as text?
There are quite a few easy ways to tell!
Left Aligned
The first way you might be able to tell if you have text values instead of numerical values is the way the data is aligned in the cell.
By default text is left aligned and numbers are right aligned.
Unless the alignment formatting has been changed from the default, this will be an easy way to spot numbers that have been formatted as text.
Green Triangle Error Checking
If you don’t realize you have numbers entered as text values, it can potentially cause some serious errors. This is why it’s flagged by Excel’s built-in error checker.
Any cells that are flagged with an error will show a small green triangle in the left of the cell to visually indicate an error.
When you select such a cell a small warning icon will appear.
When you click on this, it will show you what the error is. In this case, you can see the error is Number Stored as Text.
You can turn off this error checking entirely, or customize which errors are flagged.
Go to the File tab and then select Options at the bottom. This will open up the Excel Options menu.
In the Formula section of the Excel Options menu ➜ Error Checking.
Uncheck the Enable background error checking option to disable this feature. You can also customize the color used to indicate errors here.
Text Format Applied
One way that numbers get entered as text is when the cell has been formatted as text. This causes values to be entered as text values regardless of whether they are numerical.
There is a quick way to determine whether or not a cell has had text formatting applied.
Select the cell and go to the Home tab. You will be able to see if Text is the selected formatting in the dropdown menu found in the Number section of the ribbon.
Preceding Apostrophe
Another way that numbers can be entered as text is by using a preceding apostrophe.
When you enter an apostrophe ' as the first character in a cell, anything after will be regarded as a text value by Excel.
This means if you see a leading apostrophe in the formula bar, you know the data is a text value.
Use the ISTEXT Function
Excel has a function you can use to test if a value is a text value or not.
ISTEXT ( input )
- input is the value, cell or range which you want to test if it is text.
The ISTEXT function will return TRUE if the value is text and FALSE otherwise.
= ISTEXT ( B3 )
Here you can see the ISTEXT function being used to determine if the cells contain text. The function returns TRUE when it finds a text value.
ISNUMBER ( input )
- input is the value, cell or range which you want to test if it is a number.
Similarly, you can test if a value is a number using the ISNUMBER function. It takes a single input and returns TRUE when the value is a number and FALSE otherwise.
Here the same data is tested using the ISNUMBER function. The function returns FALSE when it does not find a number.
Status Bar Only Shows a Count
Another way to quickly test a range of cells to see if they are all text is by using the status bar.
When you select a range of numerical values, Excel will show you some basic statistics like the sum, min, max, and average in the status bar.
If they are all numbers entered as text values, then these basic statistics won’t be calculated. Instead, you will only see the count of the cells in the status bar.
Note: If just one of the cells is a numerical value, you will see the full set of statistics in the status bar.
Convert Text to Number with Error Checking
You have already seen that you can use error checking to spot numbers entered as text.
The error checking will also allow you to convert these text values into proper numbers.
Click on the Error icon and choose Convert to Number from the options. Excel will then convert each cell in the selected range into a number.
Note: This option can be very slow when you have a large number of cells to convert.
Convert Text to Number with Text to Column
Usually, Text to Columns is for splitting data into multiple columns. But with this trick, you can use it to convert text format into the general format.
Text to Column will let you choose a delimiter character to split your data based on. If you deselect this option and don’t pick any delimiter then it won’t split your data.
You are then able to choose how to format the results, and this is where you can choose a general format for the output.
Follow these steps to use the text to column feature to convert text to numbers.
- Select the cells that contain the text which you want to convert into number.
- Go to the Data tab.
- Click on the Text to Column command found in the Data Tools tab.
- Select Delimited in the Original data type options.
- Press the Next button.
- Press the Next button again in step 2 of the Convert Text to Columns wizard. You can keep the default options.
- Select General from the Column data format option.
- Select a Destination if you want to place the converted values in a new location. Otherwise you can keep the default value which should be the active cell, this will replace the text with numeric values.
- Press the Finish button.
This will convert your text values into numerical values.
The Text to Column command is usually used to split comma-separated or other delimiter separated data into multiple columns.
Any delimited data will be text data, so when Excel splits the data into multiple columns it also converts numerical data into numbers for added convenience.
This is also true even if there is nothing to split!
So the Text to Column wizard can be used to converts numerical text values to numbers.
Convert Text to Number with Multiply by 1
Even when values are stored as text you can still perform certain numerical calculations with them and the results of these calculations will also be numerical values.
You can use this to convert the text into numbers by multiplying them by 1. Since you are multiplying by 1, it won’t change the numbers but it will convert them.
= B3 * 1
You can use the above formula in an adjacent cell and copy and paste it down to convert an entire column.
If you want to remove the formula after, you can copy and paste them as values.
Convert Text to Number with Paste Special Multiply
Multiplying by 1 is a great trick for converting text to values, but you might not want to use a formula for this.
The great news is there is an easy way to multiply your text by 1 without using a formula.
This means you can convert your text in place and you don’t need to copy and paste formulas as values in an additional step.
You can use Paste Special Multiply to convert your text values. Follow these steps to multiply by 1 using Paste Special.
- Enter 1 into a cell elsewhere in the sheet. The 1 doesn’t even need to be a number value and can be a text value.
- Copy the cell which contains 1 using Ctrl + C on your keyboard or right click and choose Copy.
- Select the cells with the text values to convert.
- Press Ctrl + Alt + V on your keyboard or right click and choose Paste Special. This will open up the Paste Special menu.
- Select Values under the Paste options and select Multiply under the Operation options.
- Press the OK button.
This will multiply all the values by 1 which was the value in the copied cell. As a result, the text is converted into values, but since you are multiplying by 1 the numbers won’t change.
Convert Text to Number with VALUE Function
There is actually a dedicated function you can use for converting text to numerical values.
The VALUE function takes a text value and returns the text value as a number.
= VALUE ( text )
- text is the text value you want to convert into a numerical value.
If the text contains any non-numerical characters, then the VALUE function will return a #VALUE! error. It doesn’t extract numbers from text, it can only convert numbers entered as text into numbers.
= VALUE ( B3 )
You can use the above formula to convert the text in cell B3 into a number and then copy and paste the formula to convert the entire column.
Convert Text to Number with Power Query
Power Query is an amazing tool for any type of data transformation required. It can certainly be used to convert text into numbers as well.
Power Query is strongly typed. This means calculations with incompatible data types will result in an error. So you won’t be able to multiply text values by 1 to convert them into numbers.
But Power Query does come with an easy way to convert data types, including text to numbers.
Follow these steps once your data has been imported into Power Query.
Click on the data type icon to the left side of the column heading for the values you want to convert.
Each column in the Power Query editor has a data type icon that displays the current data type of the column. If the column has not been assigned a data type, then the icon shown will be ABC123.
There are several numeric data types available in Power Query and which one you choose will depend on the level of decimal precision you need.
In this case, you can select the Whole Number option from the menu.
Notice the values in the column are now right-aligned and the data type icon has changed? These are visual indicators that the data type is now whole numbers instead of text.
= Table.TransformColumnTypes(Source,{{"Text", Int64.Type}})
You will see a new Changed Type step has been applied to the query and it will use the above M code formula.
You can then press the Close & Load button in the Home tab to save the results and load the data into Excel.
You might not even need to apply this data type conversion step to your query. When you first import data into Power Query, it will usually guess the data type and apply the conversion for you!
Convert Text to Number with Power Pivot
If you want to analyze or summarize your data after you convert it from text to numbers, then you might want to do the conversion in Power Pivot.
Power Pivot is an add-in that allows you to efficiently analyze millions of rows in the data model with Pivot Tables.
With Power Pivot, you can build row-level calculations using the DAX formula language to create new columns in your datasets. You can then access these new columns in your pivot tables connected to the data model.
In this case, the DAX formula you can use to convert text to numbers is the exact same as the formula in the grid.
Follow these steps inside the Power Pivot add-in to create a new calculated column that converts the text to numbers.
Select any cell under the Add Column heading.
=VALUE(TextNumbers[Text])
Insert the above formula. TextNumbers is the name of the table of data in Power Pivot and Text is the name of the column you want to convert.
Double click on the column heading to change the name.
Press the Save icon and close the Power Pivot add-in.
Now you can create a pivot table from the data model and this new column will be available for use inside the pivot table just like any other field.
- Go to the Insert tab.
- Click on the PivotTable button.
- Choose From Data Model in the available options.
The calculated column will be available in your pivot table fields list and you will be able to use it like any other number field.
Conclusions
There are many reasons why you might have data that contains numbers formatted as text.
If you want to freely use these values in your calculations, you will need to convert them into numbers.
Thankfully, there are many easy options to convert text to numbers such as error checking, paste special, basic multiplication, and the VALUE function. These are all easy ways to convert text inside the grid.
If you’re importing your data using Power Query or Power Pivot, you can perform the conversion inside each of these tools. Both have methods available to convert text to numbers.
Do you use any of these methods to change your text values to numbers? Do you know any other interesting ways to perform this action? Let me know in the comments below!
About the Author
John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.