The information in this article applies to:
SUMMARYIn Microsoft Excel, you can select cells in a range either manually or by using some simple Microsoft Visual Basic for Applications code. This article provides examples you can use to select a range of cells. MORE INFORMATIONExamples of How To Select Cells ManuallyTo manually select all the data in a column, select the first cell, and press CTRL+SHIFT+DOWN ARROW.Likewise, to manually select a row and all columns attached to the row, press CTRL+SHIFT+DOWN ARROW+RIGHT ARROW. However, all data must be contiguous (that is, you cannot have blank rows or columns). Also, you can select the current region of data (contiguous data, with no blank rows or columns) by doing the following:
NOTE: If you try to record this procedure by using the macro recorder, you do not receive the same results. Examples of How to Use Visual Basic Code to Select Cells in a RangeMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspThe following Visual Basic code samples show you how to select varying ranges. If you know the beginning cell (in this example, the beginning cell is cell C1), and you want to select down to the last cell (in the same column)that has data but do not know that address, use the following code: NOTE: The SelectRangeDown macro assumes your data is contiguous.
Otherwise, if there are blank cells in the column of data you are selecting, this macro may not select all of your cells in the column.
If your data begins in cell C1, but is not contiguous in that column, use the following macro:
If you want to select from the active cell down and all columns to the
right (assuming contiguous data in all rows and columns), use the
following code:
If you know the starting cell (in this sample code, the starting cell is
D1), and you want to select down the column and to the right, try using
the following code:
To select all data in the current region, use the following code:
The examples included in this article show you how to select varying
ranges on the active worksheet of your current workbook.
For additional information about selecting ranges with Visual Basic for Applications (and for more advanced examples), please click the article number below to view the article in the Microsoft Knowledge Base: Q213651 XL2000: How to Select Cells/Ranges Using Visual Basic Procedures REFERENCESFor more information about using the End property to select cell ranges, in the Visual Basic Editor, click
Microsoft Visual Basic Help on the Help menu, type
end in the Office Assistant or the Answer Wizard, and
then click Search to view the topic. Additional query words: ranges select adjacent XL2000
Keywords : kbprg kbdta kbdtacode OffVBA PgmHowto KbVBA |
Last Reviewed: December 17, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |