Columns, Rows, and Cells of a Worksheet |
|
The Columns of a Worksheet |
Introduction to Columns |
Microsoft Excel provides easy means of creating a list. It does this by pre-defining categories of items in vertical sections called columns. Each column displays one or two letters or characters in an area referred to as the column header. The most left column has a label of A. The second has a label of B, and so on: The columns are stored in a property called Columns that belongs to the current worksheet, that is, the worksheet that accesses it. To programmatically access a column, pass the label of column header, as a single range, to the Columns collection. Consider the following code: Private Sub CommandButton1_Click() Columns("D:D") End Sub Writing Columns("D:D") allows you to access column D. To access a range of columns, pass the range to the Columns collection as a string. Consider the following code: Private Sub CommandButton1_Click() Columns("F:J") End Sub |
Practical Learning: Checking Columns |
|
Columns Selections |
Before performing an action on a column, you may have to select it first. Depending on the assignment, you may need to select more than one column. You can select a column or a group of columns using the mouse, the keyboard, a combination of both, or using code. To select a column, you can click (with the left mouse button) a column header; it would get selected and all small boxes under it. To select a column using the keyboard, click anything under it, then press and hold Ctrl. While Ctrl is down, press the Space bar and release Ctrl. You can also select more than one column. Selecting columns in a range consists of selecting adjacent columns. To perform this type of selection, you can use either the mouse or a combination of the mouse and the keyboard. To select columns in a range, click one column header and hold the mouse down. Then drag in the direction of the range. Alternatively, to select a range of columns, click one column at one end of the desired range. Press and hold Shift. Then click the column at the other end, and release the mouse. Random selection consists of selecting columns that are not adjacent. For example, this allows you to select columns B, D, and H. To do this, click one column header, press and hold Ctrl. Then click each desired column header. When you have selected the desired columns, then release the mouse. To programmatically select a column, pass the label of column header, as a single range, to the Columns collection, and call the Select() method. Consider the following code: Private Sub CommandButton1_Click() Columns("D:D").Select End Sub This allows you to select column D. To select a range of columns, pass the range to the Columns collection as a string. Consider the following code: Private Sub CommandButton1_Click() Columns("F:J").Select End Sub This code allows you to select the range of columns from F to J. |
Practical Learning: Selecting Columns |
|
|
The Records or Rows of a List |
Introduction to Rows |
As mentioned for the list of videos above, when creating a list, you typically enter a necessary piece of information under each column until you reach the right end of the list. The values that share the same line are called rows. To make it easy with the creation of a list, Microsoft Excel provides ready made rows and each is identified with a number. The most top row is numbered 1. The row under it is named 2, and so on. The gray area that displays the number of the row can be referred to as the row header. Microsoft Excel provides 65536 rows: You can use just a few of them for your assignment but all of them are always available. The records of a worksheet are stored in its Rows collection. To access a row, pass its single range to Rows. Here is an example: Private Sub CommandButton2_Click() Rows("12:12") End Sub This example indicates that you want to access row 12. To access a range of records, pass it to the Rows collection. Consider this: Private Sub CommandButton2_Click() Rows("4:18") End Sub This code indicates that you want to access the range or rows from 4 to 18.
|
Rows Selections |
As done with columns, you can select one row or a group of rows. You can also select rows at random. You can perform selections using the mouse, the keyboard, or a combination of both. To select a row, you can just click its row header. To select a row using the keyboard, click any box on its right, press and hold Shift. While Shift is still down, press the Space bar and release Shift. To select a range of rows, you can click one row header and hold the mouse down. Then drag in the direction of the range. Alternatively, to select a range of rows, click one row at one end of the desired range. Press and hold Shift. Then click the row at the other end, and release the mouse. To select rows at random, click one row header, press and hold Ctrl. Then click each desired row header. When you have selected the desired row, then release the mouse. To select a row, pass its single range to the Rows collection and call the Select() method. Consider the following example: Private Sub CommandButton2_Click() Rows("8:8").Select End Sub This code will select row 8. In the same way, to select a range or records, pass the range to the Rows collection and call the Select() method. Consider the following example: Private Sub CommandButton2_Click() Rows("6:10").Select End Sub This code will select rows from 6 to 10. |
Practical Learning: Selecting Rows |
|
A Row's Height |
To display the contents of boxes on its right, a row uses a set height. The height is the distance from the top to the lower borders of the row. To change the height of a row, you can position your mouse on its lower border, click and drag down until you get the desired height. Then release the mouse. You can also right-click a row header and click Row Height. This calls the Row Height dialog box that allows you to enter the numeric value of the desired height and press Enter. After selecting various rows, you can also change the heights of a group of rows. The height of a row or a collection is represented by the RowHeight property of the Rows collection. Based on this, to change the height of a row, pass its single selection to the Rows collection, access its RowHeight property and assign it the desired height. Here is an example: Private Sub CommandButton2_Click() Rows("16:16").RowHeight = 2.24 End Sub This example will change the height of the 16th row to 2.24. In the same way, to change the heights of various rows, pass their range to the Rows collection, access the RowHeight property and assign the desired value.
|
Practical Learning: Controlling Rows Height |
|
Hide and Unhide Rows |
As mentioned earlier, Microsoft Excel makes all of the rows of a sheet available while you are working. If at a certain time you don't need to display a certain row, you can hide it. In the same way, you can hide more than one rows. To hide a row, while that row or a box on its right is selected, on the main menu, click Format -> Row -> Hide. The row will disappear from the screen without being deleted. To unhide the row, on the main menu, click Format -> Row -> Unhide. To programmatically hide a row, first select. Then, access the Hidden property of the EntireColumn object of Selection. Consider the following example: Private Sub CommandButton2_Click() Rows("6:6").Select Selection.EntireRow.Hidden = True End Sub This code example will hide row 6. In the same way, to hide a group of rows, first select their range, then write Selection.EntireRow.Hidden = True. |
Cells |
Introduction |
A cell is a box at the intersection of a column and a row. The cell is the actual object that receives values or presents them to a user. The cells of a worksheet are stored in a collection called Range. |
Location of a cell |
Whatever you are doing on a cell, it is always important to know what cell you are working on. The minimum piece of information you need about a cell is to know which one you are using at a particular time. To make this recognition a little easier, each cell has an address also called a location. This address or location also serves as the cell's primary name. To know the location of a cell, you refer to its column and its row. The combination of the column and the row's labels provides the address or name of a cell. When you click a cell, its column header receives a border thicker than the other column headers. In the same way, the row header of a selected cell is thicker than the other row headers. To know the name of a cell, you can refer to the Name Box, which is located at the intersection of columns and rows' headers: |
Cells Selection |
Before doing anything on a cell or a group of cells, you must first select it. Selecting cells is almost equivalent to highlighting a word in a text document. And like a text document, various techniques are available here. The Active Cell Other Cells Selections To select one cell, just click it. To select another cell, click the new one. To select cells under the same column, click and hold your mouse on one cell, then drag down (or up) to the last cell. To select cells on the same row, click one of the cells, then drag right (or left) to the last cell. To select cells at random, click one of the cells involved in the selection (any of the cells), press and hold Ctrl, then click each one of the desired cells. When the cells have been selected, release Ctrl. To select cells on the same row using a combination of the mouse and keyboard, give focus to a cell on one end, press and hold Shift, then click the cell that will be at the other end. Release Shift. To select more than one cell, press and hold Shift. If you press the right arrow key, the currently highlighted cell and the cell to its right would be selected. If you press the down arrow key, the current cell and the cell under it will be highlighted. You can also press the left or up arrow key. You can press the arrow key many times in the direction of your choice. Once you have achieved the selection you want, release the Shift key. To select all cells on a worksheet, you can press Ctrl + A. Alternatively, you can click the button at the intersection of the column header and row headers. To programmatically select a cell, pass its address to the Range collection and call the Select() method. Here is an example: Private Sub CommandButton1_Click() Range("F14").Select End Sub This code will move the focus to cell F14. In the same way, to select a range of cells, pass it to the Range collection and call the Select() method. Here is an example: Private Sub CommandButton1_Click() Range("B2:D6").Select End Sub This code will select cells from B2 to D6. |
Practical Learning: Selecting Cells |
|
The Width of a Cell |
A cell in a Microsoft Excel worksheet doesn't have dimensions of its own. It uses those imposed to it. Since at least one cell in the worksheet always has focus, to change the column width under which that cell is selected, on the main menu, you can click Format -> Columns. You have a lot of options:
We saw earlier how to change the width of a column. This also allows you to change the width of cells under that column. To use AutoFit Selection, first give focus to the cell that contains the value used as reference, then call the AutoFit() method of the Columns property of the Selection object. It can be called as follows: Private Sub CommandButton1_Click() Selection.Columns.AutoFit End Sub This code will check the value of the selected cell and will resize the column to automatically fit that cell.
|
Practical Learning: Setting Column Width Using Cells |
|
Cells Names |
We saw that a cell, each cell, has a name, which is also its location, which is provided by a combination of its parent column and its parent row. Instead of using the column and row to identify a cell, Microsoft Excel allows you to change the name of a cell to your liking. In fact, you can combine cells and name the group to anything you like. To change the name of a cell, first click it. Then, in the Name Box, replace the name with the desired name and press Enter. Alternatively, to create a new name for a cell, first select it. Then, on the main menu, click Insert -> Name -> Define... In the Names In Workbook text box of the Define Name dialog box, type the desired name and click OK. To change the name of a group of cells, first select them, using the techniques we learned for selecting cells. Then, in the Name Box, replace the string with the new name. In the same way, to create a name for a group of cells, after selecting them, on the main menu, click Insert -> Name -> Define... In the Names In Workbook text box of the Define Name dialog box, type the desired name and click OK. |
Practical Learning: Naming Cells |
|
Previous | Copyright © 2002-2007 FunctionX, Inc. | Next |