# Extracting Numbers within a Range by Allen Wyatt
(last updated February 17, 2020)

Robert has a series of numbers in column A that range from 1 to 100. He would like to extract only those values between 65 and 100, inclusive, and place them in column B. He wonders if there is a way to do that easily.

The short answer is that there is a very easy way to do it, provided you don't mind sorting the list of numbers. Follow these steps:

1. Select a cell in column A. (It doesn't really matter which cell you select, as long as it is one of the cells that contains a number.)
2. Display the Data tab of the ribbon.
3. Click the Sort Smallest to Largest tool, in the Sort & Filter group. Excel sorts all the numbers in the column.
4. Select the numbers that you want to put into column B.
5. Press Ctrl+X to cut the cells to the Clipboard.
6. Select cell B1 (or the first cell in column B where you want the values to appear).
7. Press Ctrl+V to paste the cells into the column.

That's it; you've now got the desired cells into column B. If you simply wanted to copy the cells, then in step 5 you could have pressed Ctrl+C instead.

If you need to keep the values in column A in their original order (minus the values you want to move), you can do it by using column B as a "place retainer" column. To the right of the first value in column A, put the vaue 1. Then, below that in column B put a 2, then a 3, and so on, until each value in column A has a corresponding value in column B that indicates the numbers location. Then, follow these steps:

1. Select a cell in column A. (It doesn't really matter which cell you select, as long as it is one of the cells that contains a number.)
2. Display the Data tab of the ribbon.
3. Click the Sort Smallest to Largest tool, in the Sort & Filter group. Excel sorts all the numbers in the column.
4. Select the numbers in column A that you want to move, along with the numbers to the right of them in column B.
5. Press Ctrl+X to cut the cells to the Clipboard.
6. Select cell D1. (It is important to select cell D1 because you need to leave column C blank.)
7. Press Ctrl+V to paste the cells into columns D and E.
8. Select a cell in column B.
9. Display the Data tab of the ribbon.
10. Click the Sort Smallest to Largest tool, in the Sort & Filter group. Excel sorts all the numbers in the column based on the values in column B.
11. Select a cell in column E.
12. The Data tab of the ribbon should still be displayed.
13. Click the Sort Smallest to Largest tool, in the Sort & Filter group. Excel sorts all the numbers in the column based on the values in column E.
14. Delete columns B, C, and E.

At this point the values in columns A and B reflect their original order, from when they were all in column A.

Another way to move the cells is to use the filtering capabilities of Excel. Follow these steps:

1. Select a cell in column A. (It doesn't really matter which cell you select, as long as it is one of the cells that contains a number.)
2. Display the Data tab of the ribbon.
3. Click the Filter tool. Excel adds a filter drop-down arrow at the right side of the column A header.
4. Click the down-arrow and choose Number Filters | Between. Excel displays the Custom AutoFilter dialog box. (See Figure 1.)
5. Figure 1. The Custom AutoFilter dialog box.

6. In the Greater Than or Equal To box, enter 65.
7. In the Less Than or Equal To box, enter 100.
8. Click OK. Excel limits what is shown to only those rows that meet the criteria you specified in steps 4 through 6.
9. Select the cells that are displayed.
10. Press Ctrl+C to copy the cells to the Clipboard.
11. Select cell B1 (or the first cell in column B where you want the values to appear).
12. Press Ctrl+V to paste the cells into the column.
13. Select one of the cells in column A.
14. Again click the Filter tool. (The Data tab of the ribbon should still be displayed.) Excel removes the filter you previously applied.

You could also use formulas in column B to pull out the values that are within the desired range. An easy way to do this is to place this formula in cell B1:

```=IF(AND(A1>=65, A1<=100),A1,"")
```

Copy the formula down as far as necessary in column B and you end up with any values in the range of 65 to 100, inclusive, being "copied" into column B. If the value is outside this range, then the cell in column B is left empty.

Assuming that you don't want any empty cells in column B, then you could use an array formula to grab the values. If your values are in the range A1:A500, place the following in cell B1:

```=IFERROR(INDEX(A\$1:A\$500,SMALL(IF(A\$1:A\$500>=65,ROW(\$1:\$500)),ROW())),"")
```

Enter it using Ctrl+Shift+Enter, and then copy the formula down as far as you'd like.

There are, of course, macro-based solutions you can use. These are helpful if you need to perform this task quite a bit with data that you retrieve from an outside source. The following is a simple example of a macro you could use:

```Sub ExtractValues1()
Dim x As Integer

x = 1
For Each cell In Selection
If cell.Value >= 65 And cell.Value <= 100 Then
Cells(x, 2) = cell.Value
x = x + 1
End If
Next cell
End Sub
```

You use the macro by selecting the cells you want evaluated in column A and then running it. It looks at each cell and copies the value to column B. The original value in column A is left unchanged.

For more flexibility you could rely on asking the user for the lower and upper values, as shown in this macro:

```Sub ExtractValues2()
Dim iLowVal As Integer
Dim iHighVal As Integer

iLowVal = InputBox("Lowest value wanted?")
iHighVal = InputBox("Highest value wanted?")

For Each cell In Range("A:A")
If cell.Value <= iHighVal And cell.Value >= iLowVal Then
ActiveCell.Value = cell.Value
ActiveCell.Offset(1, 0).Activate
End If
Next
End Sub
```

Before you run the macro, select the cell at the top of the range where you want the extracted values placed. Nothing in column A is affected; only the values between the lower and upper range are copied to the new location.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13397) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Returning the MODE of a Range

The MODE function is used to determine the most frequently recurring value in a range. This tip explains how to use the ...

Discover More

Calculating Average Word Length

Word keeps track of many statistics about your documents. The problem, it seems, is getting exactly the statistics you ...

Discover More

Problems Pasting Information into a Worksheet

What do you do if pasting information into a worksheet brings Excel to its knees? This tip looks at just a few ideas you ...

Discover More Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

##### More ExcelTips (ribbon)

Deleting All Names but a Few

Want to get rid of most of the names defined in your workbook? You can either delete them one by one or use the handy ...

Discover More

Editing Individual Cells

Need to edit the data within a cell? There are any number of ways you can perform the edit; this tip documents them all.

Discover More

Moving and Copying Cells

At the very heart of editing is the ability to move and copy cells in a worksheet. Understanding the differences between ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven minus 5?

2019-09-12 10:12:56

Peter Atherton

Aaron
The best way to get duplicate values is show @ https://exceljet.net/formula/get-nth-match-with-index-match. The page show the logic behind it as well. Here is my own version that gets person's sales between two dates. It is committd with Ctrl + Shift + Enter so making it an array formula.
=IFERROR(INDEX(\$D\$2:\$D\$30,SMALL(IF((\$I\$2=\$A\$2:\$A\$30)*(\$J\$2<=\$B\$2:\$B\$30)*(\$K\$2>=\$C\$2:\$C\$30),ROW(\$D\$2:\$D\$30)-ROW(\$D\$2)+1),ROW(1:1))),"")

The image shows the data

(see Figure 1 below) Figure 1.

2019-09-11 05:34:46

Aaron Casper

Hi all

i need to extract data in a range, this formula is working fine but its not showing duplicate values. is there any chance that i get duplicate value too?

=INDEX(\$B\$36:\$V\$36,MATCH(1,INDEX((\$B\$36:\$V\$36=LARGE(\$B\$36:\$V\$36,ROWS(AB\$7:AB13)))*(COUNTIF(AB\$7:AB13,\$B\$36:\$V\$36)=0),),0))

2019-05-01 09:45:59

Jeffrey Harrison

First of all thank you for this. It was almost exactly what I needed. The only issue I had was when using the INDEX function you couldn't have a header row on the column and the information I wanted was in a different column than my numbers. After playing around with the formula I figured out a way to make it work. This builds off Russell Gorton's example in his comment...

For being able to have a header row...

{=IFERROR(INDEX(A\$2:A\$55,SMALL(IF((A\$2:A\$16>=65)*(A\$2:A\$55<101),ROW(\$1:\$54)),ROW()-1)),"")}

And if the value you want is in a different field than the numbers you are testing against...

{=IFERROR(INDEX(B\$2:B\$55,SMALL(IF((A\$2:A\$16>=65)*(A\$2:A\$55<101),ROW(\$1:\$54)),ROW()-1)),"")}

2016-11-14 16:30:57

Nathan Gruetzmacher

Hello, i have a similar question, but instead of returning numbers in a given range, I want to extract the only number. I have a column that has about 9 cells. They are dependent upon a gross income amount and they calculate taxes paid depending on which bracket your salary falls in. I can not get a function that will search through that array for the numeric value, and return it. How can i make it search the array and return a number that I do not specify?

Thank you,
Nathan

2015-08-24 05:47:40

Russell Gorton

The array formula shown above doesn’t implement the condition that numbers be 100 or less, i.e between 65 and 100. To achieve this it could be amended to:
=IFERROR(INDEX(A\$1:A\$54,SMALL(IF((A\$1:A\$54>=65)*(A\$1:A\$54<101),ROW(\$1:\$54)),ROW())),"")
Or
=IFERROR(INDEX(A\$1:A\$54,SMALL(IF(A\$1:A\$54>=65,IF(A\$1:A\$54<101,ROW(\$1:\$54))),ROW())),"")

2015-08-08 14:06:24

Steve Symes

Also you could just put this formula in B1:
If(A1>64,A1,"")
and copy this formula down column B as far as required

2015-08-08 12:11:09

Robert Lilly

Thank you Allen, I want to express my apparition for your response to my question. And also for the time it took you to put together this fantastic example on how to resolve my problem.

Every day I look forward to receiving your Excel Tips, Word Tips and the weekend tips as well.

Again thank you very much.

Bob Lilly

2015-08-08 11:13:14

Ken Maltese

I often have to do something similar but with extra criteria (over 30 days past due, over \$50) for example. This is just a version of #4 above such as =IF((AND(\$P5<\$P\$3,\$P5>\$Q\$3)),K5,"") where \$P\$3 is say 90 days overdue and \$Q\$3 is 30 days overdue and P5 is the payment date and K5 is the \$. Copy this over the column and put =sumif(R5:R1000>">50") to add arrears greater than \$50 or =countif(R5:R1000">50") to get the number of accounts. Since the accounts are in numerical order, I can sort out greater detail using a vlookup function to isolate accounts >90 days from the acocunts >30 days into a seperate table for example. I don't know the criteria Robert is using to get his data but hope this helps.

##### This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.