UNIT 3 Sorting and Filtering
UNIT 3 Sorting and Filtering
You can sort data by text (A to Z or Z to A), numbers (smallest to largest or largest to
smallest), and dates and times (oldest to newest and newest to oldest) in one or more
columns. You can also sort by a custom list you create (such as Large, Medium, and
Small) or by format, including cell color, font color, or icon set.
Notes:
• To find the top or bottom values in a range of cells or table, such as the top
10 grades or the bottom 5 sales amounts, use AutoFilter or conditional
formatting.
• For more information, see Filter data in an Excel table or range, and Apply
conditional formatting in Excel .
Sort text
2. On the Data tab, in the Sort & Filter group, do one of the following:
• Check that all data is stored as text: If the column that you want to sort
contains numbers stored as numbers and numbers stored as text, you need
to format them all as either numbers or text. If you do not apply this format,
the numbers stored as numbers are sorted before the numbers stored as
text. To format all the selected data as text, Press Ctrl+1 to launch the
Format Cells dialog, click the Number tab and then, under Category, click
General, Number, or Text.
• Remove any leading spaces: In some cases, data imported from another
application might have leading spaces inserted before data. Remove the
leading spaces before you sort the data. You can do this manually, or you
can use the TRIM function.
Sort numbers
2. On the Data tab, in the Sort & Filter group, do one of the following:
Notes:
• Potential Issue
• Check that all numbers are stored as numbers: If the results are not what
you expected, the column might contain numbers stored as text instead of
as numbers. For example, negative numbers imported from some accounting
systems, or a number entered with a leading apostrophe (') are stored as
text. For more information, see Fix text-formatted numbers by applying a
number format.
Sort dates or times
2. On the Data tab, in the Sort & Filter group, do one of the following:
• Check that dates and times are stored as dates or times If the results
are not what you expected, the column might contain dates or times stored
as text instead of as dates or times. For Excel to sort dates and times correctly,
all dates and times in a column must be stored as a date or time serial
number. If Excel cannot recognize a value as a date or time, the date or time
is stored as text. For more information, see Convert dates stored as text to
dates.
• If you want to sort by days of the week, format the cells to show the day of
the week. If you want to sort by the day of the week regardless of the date,
convert them to text by using the TEXT function. However, the TEXT function
returns a text value, so the sort operation would be based on alphanumeric
data. For more information, see Show dates as days of the week.
Note: For best results, the range of cells that you sort should have column headings.
3. In the Sort dialog box, under Column, in the Sort by box, select the first
column that you want to sort.
4. Under Sort On, select the type of sort. Do one of the following:
5. Under Order, select how you want to sort. Do one of the following:
6. To add another column to sort by, click Add Level, and then repeat steps
three through five.
7. To copy a column to sort by, select the entry and then click Copy Level.
8. To delete a column to sort by, select the entry and then click Delete Level.
9. To change the order in which the columns are sorted, select an entry and
then click the Up or Down arrow next to the Options button to change the
order.
Entries higher in the list are sorted before entries lower in the list.
Sorting Excel cells by colour is the easiest task compared to counting, summing and
even filtering. Neither VBA code nor formulas are needed. We are simply going to use
the Custom Sort feature available in all modern versions of Excel 2016, 2013, 2010
and 2007.
2. On the Home tab > Editing group, click the Sort & Filter button and
select Custom Sort...
3. In the Sort dialog window, specify the following settings from left to right.
o The column that you want to sort by (the Delivery column in our
example)
o To sort by Cell Color
o Choose the color of cells that you want to be on top
o Choose On Top position
4. Click the Copy Level button to add one more level with the same settings
as the first one. Then, under Order, select the color second in priority. In the
same way add as many levels as many different colors are in your table.
5. Click OK and verify if your rows have got sorted by color correctly.
In our table, the "Past Due" orders are on top, then come "Due in" rows, and
finally the "Delivered" orders, exactly as we wanted them.
Tip: If your cells are colored with many different colors, it is not necessary
to create a formatting rule for each and every one of them. You can create
rules only for those colors that really matter for you, e.g. "Past due" items in
our example and leave all other rows in the current order.
If sorting cells by only one color is what you are looking for, then there's even a quicker
way. Simply click on the AutoFilter arrow next to the column heading you want to sort
by, choose Sort by color from the drop down menu, and then select the color of cells
that you want to be on top or at the bottom. BTW, you can also access the "Custom
Sort" dialog from here, as you can see in the right hand part of the screenshot below.
Sort cells by font color in Excel
In fact, sorting by font colour in Excel is absolutely the same as sorting by background
color. You use the Custom Sort feature again (Home > Sort & Filter > Custom
Sort…), but this time choose Font Color under "Sort on", as shown in the screenshot
below.
If you want to sort by just one font color, then Excel's AutoFilter option will work for
you too:
Apart from arranging your cells by background colour and font color, there may a few
more scenarios when sorting by color comes in very handy.
For example, we can apply conditional formatting icons based on the number in
the Qty. column, as shown in the screenshot below.
As you see, big orders with quantity more than 6 are labeled with red icons, medium
size orders have yellow icons and small orders have green icons. If you want the most
important orders to be on top of the list, use the Custom Sort feature in the same way
as described earlier and choose to sort by Cell Icon.
It is enough to specify the order of two icons out of 3, and all the rows with green icons
will get moved to the bottom of the table anyway.
How to filter cells by color in Excel
If you want to filter the rows in your worksheet by colors in a particular column, you
can use the Filter by Color option available in Excel 2010, Excel 2013, and Excel 2016.
The limitation of this feature is that it allows filtering by one color at a time. If you want
to filter your data by two or more colours, perform the following steps:
1. Create an additional column at the end of the table or next to the column
that you want to filter by, let's name it "Filter by color".
As a result, you will get the following table that displays only the rows with the two
colors that you selected in the "Filter by color" column.