0% found this document useful (0 votes)
6 views

UNIT 3 Sorting and Filtering

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

UNIT 3 Sorting and Filtering

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

UNIT 3

Sorting and Filtering Data in Excel

Sort data in a range or table


Sorting data is an integral part of data analysis. You might want to arrange a list of
names in alphabetical order, compile a list of product inventory levels from highest to
lowest, or order rows by colors or icons. Sorting data helps you quickly visualize and
understand your data better, organize and find the data that you want, and ultimately
make more effective decisions.

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

1. Select a cell in the column you want to sort.

2. On the Data tab, in the Sort & Filter group, do one of the following:

o To quick sort in ascending order, click (Sort A to Z).

o To quick sort in descending order, click (Sort Z to A).


Notes: Potential Issues

• 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

1. Select a cell in the column you want to sort.

2. On the Data tab, in the Sort & Filter group, do one of the following:

o To sort from low to high, click (Sort Smallest to Largest).

o To sort from high to low, click (Sort Largest to Smallest).

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

1. Select a cell in the column you want to sort.

2. On the Data tab, in the Sort & Filter group, do one of the following:

o To sort from an earlier to a later date or time, click (Sort Oldest


to Newest).

o To sort from a later to an earlier date or time, click (Sort Newest


to Oldest).

Notes: Potential Issue

• 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.

Sort by more than one column or row


You may want to sort by more than one column or row when you have data that you
want to group by the same value in one column or row, and then sort another column
or row within that group of equal values. For example, if you have a Department
column and an Employee column, you can first sort by Department (to group all the
employees in the same department together), and then sort by name (to put the
names in alphabetical order within each department). You can sort by up to 64
columns.

Note: For best results, the range of cells that you sort should have column headings.

1. Select any cell in the data range.


2. On the Data tab, in the Sort & Filter group, click Sort.

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:

o To sort by text, number, or date and time, select Values.

o To sort by format, select Cell Color, Font Color, or Cell Icon.

5. Under Order, select how you want to sort. Do one of the following:

o For text values, select A to Z or Z to A.

o For number values, select Smallest to Largest or Largest to


Smallest.
o For date or time values, select Oldest to Newest or Newest to
Oldest.

o To sort based on a custom list, select Custom List.

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.

Note: You must keep at least one entry in the list.

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.

Sort by cell color in Excel

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.

1. Select your table or a range of cells.

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.

Sort by cell icons

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".

2. Enter the formula =GetCellColor(F2) in cell 2 of the newly added "Filter by


color" column, where F is the column congaing your colored cells that you
want to filter by.

3. Copy the formula across the entire "Filter by color" column.


4. Apply Excel's AutoFilter in the usual way and then select the needed colors
in the drop-down list.

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.

You might also like