:: Subscribe to our newsletter
 
Articles / Directory
06/17/2013
Latest version of TraderCode(v5.6) includes new Technical Analysis indicators, Point-and-Figure Charting and Strategy Backtesting.



06/17/2013
Latest version of NeuralCode(v1.3) for
Neural Networks Trading.



06/17/2013
ConnectCode Barcode Font Pack - enables barcodes in office applications and includes an add-in for Excel that supports mass generation of barcodes.



06/17/2013
InvestmentCode, a comprehensive suite of
Financial calculators and models for Excel is now available.



09/01/2009
Launch of
Free Investment and Financial Calculator for Excel.



02/1/2008
Release of
SparkCode Professional - add-in for creating Dashboards in Excel with sparklines



12/15/2007
Announcing
ConnectCode Duplicate Remover - a powerful add-in for finding and removing duplicates entries in Excel



09/08/2007
Launch of
TinyGraphs - open source add-in for creating sparklines and tiny charts in Excel.



Other Excel Add-In, Templates and Training

Lesson 8

DATA SORTING / HIDE AND UNHIDE
AUTOFORMATS

Download Workbook for this lesson

Sorting

Data sorting is an extremely handy and versatile feature within Excel. The sorting feature is found by going to Data>Sort to access the Sort dialog box. Generally, sorting is performed on a list, which is defined as a contiguous (no blank cells) group of data where the data is displayed in columns and/or rows. Excel allows you to sort Worksheet data alphabetically, numerically or chronologically. You can sort by columns, by rows, in an ascending or descending order and from left to right. When you sort within Excel, it will rearrange the contents of the sort area according to the instructions that you give it. Excel will always sort blank cells to the bottom of a list.

There are a few basic rules that you need to follow when setting up your list in the first place. These are:

  • Check that any numbers in your spreadsheet are in a numerical format.

  • Cells containing both text and numbers need to be formatted as text.

  • Dates and times must be formatted correctly.

  • You must unhide any hidden rows or columns (we will cover hiding rows and columns later in this lesson).

  • Make sure you have no leading spaces. This can happen when you push your Space bar before typing into the cell.

  • Enter column labels in one row (use Alt + Enter to put a hard return in if you need to) or use the Orientation feature under Format>Cells-Alignment.

Excel has specific sort orders to arrange data within your Worksheet according to the value (not the format) of the data. If you performed an ascending sort, numbers would be sorted from the smallest negative number through to the largest positive number. If you performed a descending sort, numbers would be sorted in reverse.

Sorting Alphanumeric Text

If you performed an ascending (lowest to highest) sort on alphanumeric text, Excel will sort your data from left to right, character by character. For example, if a cell contained the text B200, Excel will place the cell after a cell that contains the entry B2 and before a cell that contained the entry B22.

Text that includes numbers and normal text are sorted in the following order:

0 1 2 3 4 5 6 7 8 9 (space) ! " # $ % & ( ) * , . / : ; ? @ [ \ ] ^ _ ` { | } ~ + < = > A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Apostrophes (') and hyphens (-) are ignored, with one exception; if two text strings are the same except for a hyphen, the text with the hyphen is sorted last.

If you are sorting logical values, FALSE will always be sorted before TRUE and if you are sorting error values, they are all equal. We will be covering logical values in the last lesson when we look at the IF function.

As a tip, although it is not really necessary with the fabulous and very handy Undo feature, it is a good idea to save your Workbook prior to performing a sort, just in case.

Letís have a go at performing some different types of sorts.

Single Column Sort

  • Open the Workbook ExcLev1L08.xls.

  • Make sure you are on the Sorting with Text sheet tab.

  • Click in cell D5.

  • Go to Data>Sort to display the Sort dialog box. You will notice here that when you do this, your list will be highlighted (not including the headings). This is, because you are clicked in a cell within the list, Excel will search in all directions from your active cell for the end of the list. The end of the list is deemed to be the first blank cell encountered in all directions, up, down, left and right. If you manually highlight your data and Excel sees there is data immediately to the left, right, top of bottom Excel will ask if you wish to include the data.

  • Notice in the top box Sort By you have the column heading Staff Payroll No. displayed.

  • Click the drop down arrow to the right of the Sort By box and you will see the other column headings from your list.

  • We wish to leave the default Last Name as our choice as this was the column that we have clicked in.

  • Ensure the Ascending option box is ticked.

  • At the bottom of the Sort dialog box under My List has make sure that Header row is selected. If you had No header row selected, Excel would include the headings in your list as part of the sort operation.

  • Click on OK to sort your data by Last Name.

You will notice now that the Last Name column is sorted in alphabetical order, from the lowest value to the highest value.

Letís reverse the order from Ascending to Descending.

There are two ways you can do this.

  • Stay clicked in cell D5.

  • Go to Data>Sort to display the Sort dialog box.

  • Ensure the Descending option box is ticked.

  • Click on OK to sort your data by Last Name in Descending order.

OR

  • Click the Sort Descending tool, which is the Z on top of the A next to a downward pointing arrow on your Standard toolbar.

By selecting this icon, you can effectively by-pass the Sort dialog box and perform a Descending sort. You will note that to the left of the Sort Descending icon is the Sort Ascending icon. If you have previously performed a sort on a list, Excel will remember the last sort that you did, but be aware that if you are uncertain of the last sort, your list data may not sort as you expect. In other words, if you are using a file or computer that is shared, it is always best to use the Sort dialog box.

Sorting by Multiple Columns

When you perform a multiple column sort, each column is sorted one at a time. The list will be sorted by the first column then Excel will check each of the entries to see if there are duplicates. If there are, then the duplicates will be sorted by the second column and so forth.

  • Click in cell E5.

  • Select Data>Sort to display the Sort dialog box.

  • Click on the drop down arrow to the right of the Sort by: box to see the other column headings.

  • Click on Department.

  • Select the Ascending option.

  • Select the drop down arrow to the right of the Then By: box.

  • Select Last Name from the list.

  • Select the Ascending option.

  • Click on OK.

Now you have performed a sort on more than one column, let us have a look at sorting numbers. These will work just as efficiently as text when performing a sorting operation.

Sorting Numbers

Letís find out which Department generated the most income during the month of June.

  • Click on the Sorting with Numbers worksheet tab.

  • Click in cell G5.

  • Select Data>Sort.

  • Ensure that the Sort By box has June in it.

  • Select Ascending order.

  • Select OK.

  • Now click in cell A5 and we will sort the list by Departments.

  • Select your Descending icon on your Standard Toolbar.

As you can see, sorting is a very simple operation to perform with either text or numbers. You can also sort from left to right in rows, this is a little trickier, but you will find it a very handy feature to know. Let's have a go at performing a left to right sort on our Sorting with Numbers Worksheet.

  • Highlight the range B5:G12. Quick way Ė click in B5, move the mouse over cell G12, hold down the shift key and press your left mouse button Ė quick and easy.

  • Go to Data>Sort to display the Sort dialog box.

  • Click on the Options button to see a list of options available to you.

  • Under Orientation select Left to Right.

  • Click on OK to return you to the Sort dialog box.

  • In the Sort by box, click on the downward pointing arrow to the right and select Row 12.

  • Click OK.

As you can see, sorting, once mastered, can be a huge benefit to a user. Remember to set up your data in a list. That is with column headings (defined in some way, such as bolded and centered) and without any blank cells, rows or columns. If you donít, your sorting operation can turn into a nightmare! Remember the very handy undo key that you can use if you make an error, however, it is a good habit to get into to save your Worksheet first before performing a sort.

Hiding and Unhiding Rows and Columns

A very handy feature of Excel is its ability to hide rows and columns from a user without it affecting calculations in any way. This can be handy if you wish to hide calculations or certain information from a user. Hiding rows or columns can be performed in two ways, by selecting the row or column you wish to hide and going to Format>Row (or Column) >Hide or by selecting the row or column that you wish to hide, right clicking and selecting Hide.

Letís have a look at this now.

  • On a new Worksheet, click in B2 and type 100. In C2 type 100, in D2 type 100, in E2 type 100, in F2 type 100.

  • Click in G2 and use the AutoSum feature on your Standard Toolbar to sum the range B2:F2.

  • Select the entire column D by selecting the column reference (the D with the grey background).

  • Go to Format>Column>Hide.

  • You will notice now that column D has disappeared, but the result of your formula, 500 has not changed.  This is because you have only hidden the column, not deleted it.

Lets unhide the column now.

  • Highlight the entire columns C and D go to Format>Column>Unhide.

  • Notice that you have now unhidden column D.

As mentioned above, you can also perform the hide/unhide operation by right clicking and selecting either Hide or Unhide from the shortcut menu. This is my preferred option, but it is up to you which one you use.

Lets have a go at hiding some rows, using the right click option.

  • In B3 type 100, in B4 type 100, in B5 type 100, in B6 type 100, B7 type 100.

  • In B8 use the AutoSum feature to sum the range B3:B7.

  • Now select the entire row 3 by selecting the row reference.

  • Right click and select Hide.

  • Select the entire row 5 by selecting the row reference.

  • Right click and select Hide.

You should now have two rows hidden, but your formula result will still be 500.

Lets unhide the rows now.

  • Highlight rows 2 to 7.

  • Right click and select Unhide.

You can also hide sheets using Format>Sheet>Hide. You need to be aware that the right click option is not available if you wish to hide a sheet. You must do it via Format>Sheet. As with hidden rows and columns you can still reference the hidden sheet via a formula and have it return the correct value. Of course though it is wise to reference the sheet while it is visible and use the mouse pointing method to build your reference and then hide it.

If you go to Format>Sheet>Hide and the UnHide is greyed out this means there are no Worksheets hidden within the Workbook. If there are sheets hidden the Hide will not be greyed out and selecting it will display the Unhide dialog box. Within this box will be the names of all hidden sheets, to unhide one simply select the sheet name from the box and clicks OK or double click it (the sheet name).

AutoFormats

Another very handy feature of Excel is itís ability to use its built-in AutoFormats on your data, and the flexibility that you have in changing these to suit your personal taste. There are many AutoFormats available to you and they are found under Format>AutoFormat. Lets have a look at how this would work with our previous Workbook Data Sorting.

  • Open the Workbook Data Sorting.

  • Click on the Sorting with Text sheet tab.

  • Click on cell D5 or any other single cell within your list.

  • Select Format>AutoFormat and the AutoFormat dialog box will pop up in front of you. Note here that as when doing a sort operation, Excel will automatically highlight your whole table for you (it will only do this if there are NO blank columns or rows).

  • Scroll through the list of formats available to you using the vertical scroll bar, or you can use the arrow keys on your keyboard if you prefer.

  • Select List 2 by clicking on it, then select OK.

You should note that if you select more than one cell before going to Format>AutoFormat Excel will assume you only want to format the selected cells and not any surrounding data.

By using the Options button on the AutoFormat dialog box, you can make many more formats available to you. The options available to you through this button will be Number, Border, Font, Patterns, Alignment, Width/Height. Note however, that by default all options are selected, which means that all current formatting in your selected table or range will be overridden by the AutoFormats. By deselecting certain options, you will have the ability to go back into your range or table and manually apply the format attributes you have unchecked in the Formats to Apply box. However, we suggest only doing this if really necessary.

  • Make sure you are still selected somewhere in your data.

  • Go to Format>AutoFormats.

  • Select Options.

  • You will notice that the AutoFormats dialog box has now expanded to include Formats to Apply.

  • Uncheck the Number option and see how the numbers now look. You will notice the most changes in the Accounting formats (Accounting 1, Accounting 2, Accounting 3, Accounting 4).

  • By unchecking the Border checkbox, you are removing the outline of the cells as shown in the AutoFormats preview window.

  • By unchecking the Font checkbox, you are unchecking the attributes to the font that are applied to the AutoFormat which basically includes font size, font type, colour and bolding, italics etc.

  • By unchecking the Patterns checkbox you will remove the background colour and/or any patterns that may be applied.

  • By unchecking the Alignment checkbox you will change the alignment of your text or number within the cells.

  • By unchecking the Height/Width checkbox you are changing the height and width of the columns and rows. Basically, having this option checked means that your columns and rows are set to AutoFit, which is probably the best option to have.

Once you are happy with your selection, simply click OK to see exactly how your data will look.

If after applying an AutoFormat and adjusting accordingly, you decide you no longer want it, simply select any single cell within your data list, go to Formats>AutoFormats and use the scroll bar to scroll to the very bottom of the list and click None then OK.

Note however, that while applying an AutoFormat to your range will override any formatting you have previously applied, removing it does not return it to its original state.

Goto Next Lesson


Back to Excel Add-in, Templates and Training Main Page


Special :
Get the Excel VBA Training for free when you purchase our Technical Indicators now!


 

Copyright (c) 2007-2014, ConnectCode Pte Ltd. All Rights Reserved.


Trademark Acknowledgements

Microsoft and Microsoft Excel are registered trademarks of Microsoft Corporation. Avery is the trademark of Avery Dennison Corporation. All other product names are trademarks, registered trademarks, or service marks of their respective owners