How to delete rows not in filter
Emily Wong
I have a very large table in Excel (1000's of rows) and I filter it to only show 10 rows.
I wonder if there is a way to delete the rows not shown (i.e. don't meet filter conditions)? This would enable me to reduce the file size before I send it.
There are many thousands of rows down under the table the user has created complex formulas and graphs which wont carry if I copy across to another worksheet if I just copy the rows.
27 Answers
Try this way for a quick solution:-
- Copy the filtered 10 results into another sheet
- Delete the actual sheet
EDIT:
As per the update, below are the steps:-
- Before starting, take a backup copy of excel sheet
- Assuming you are filtered all the records and showing only 10 Rows
- Remaining 1000's are hidden
- Click on Office Button
- Click on Prepare option
- Click on Inspect Document
- Refer this screenshot, how it looks
- Click on Inspect button
- You will see a option "Hidden Rows and Columns" with "Remove All" button
- Click on Remove All button
- Click on close button
- Finally if you see, it has removed all "Hidden Rows and Columns"
Refer this screenshot
Note:
In Office 2010, Inspect Document can be found here:
The way that worked for me was, assuming the filter is easy to reverse:
- Clear your filter.
- Create a temporary column, say called 'TEMP ORDER'.
- Set every value in that column to 0
- Reverse your filter (filter for everything you want to delete)
- Set every value in the 'TEMP ORDER' column to 1 on the filtered results
- Clear your filter.
- Sort your data by the 'TEMP ORDER' column, smallest to largest.
- Find on which row the first '1' occurs
- Resize your table (Design tab), having the last row be the row before the first '1'
- Delete the rows that are no longer in your table.
This may be a preferable solution if you don't want to mess up any other sheets in your workbook and are concerned about what might happen if you copy and paste your data around.
1Why not just copy visible cells to a new sheet? Go to:
quick access tool bar drop down → more commands → commands not in the ribbon → select visible cells → add
When you click this it will select everything that is visible and you can copy and paste everything that's visible.
2The accepted Answer above relating to "inspect document" is excellent.
In addition, the procedure indicated would apply to the whole workbook, so you might be messing other worksheets in the same workbook. In this case, you have to move the worksheet to a separate workbook, apply the procedure, and move the worksheet back to your original workbook. Cross linking of references/formulas/chart series among worksheets, involving the worksheet in question, might be a challenge.
As an alternative to this other answer (which cannot handle the case of charts, etc., as requested by the OP), Home -> Find & Select -> Go To Special -> Visible cells only. It appears to be exactly the same command (and then I wonder why it is listed under Commands Not in the Ribbon).
1I had this exact same problem. To solve:
- Highlight the 10 rows that you want to keep and change their background color
- Clear all filters
- Apply a new filter on one of the columns, select "Filter by Color". Instead of picking the color that you used, pick "no fill".
- This brings up all of the unwanted rows. Highlight them all and delete.
- Remove the filter and you'll be left with just the 10 rows that you want. All charts and cell references will be in tact.
Easy... I had the same problem.
- Select All in the filter and untick all unwanted info and click OK.
- Clear all filters. (You will notice that all rows that were unticked are now highlighted.)
- Press Ctrl- to delete those rows.
This might be overly simplistic but why not just copy/paste the 10 rows you've filtered down to into a new spreadsheet?
1