Microsoft KB Archive/89949

= Macro to Select all Data on a Worksheet =

Article ID: 89949

Article Last Modified on 11/16/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition
 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q89949



SUMMARY
In Microsoft Excel, you can select all the data on your worksheet by pressing the key combination CTRL+SHIFT+END (CONTROL+SHIFT+END on Macintosh). You can also simulate these keystrokes in the macro described in this article.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

Sample Visual Basic Procedure
The following procedure selects data from the currently selected cell, to the end of the data on your worksheet. Sub Select_All Range(Selection, Selection.SpecialCells(xlLastCell)).Select End Sub You can easily modify the procedure to select from a specific cell by adding the following statement to the beginning of the procedure:

Range(&quot;B2&quot;).Select

where B2 is the reference of the specific cell.

Microsoft Excel version 4.0 Macro
The following macro selects data from the currently selected cell, to the end of the data on your worksheet. You can easily modify the macro to select from a specific cell by changing the SELECT function in cell A2 to select the starting cell you want.

For example, to select from the first cell (R1C1) on your worksheet, change the SELECT function in A2 to read: =SELECT(&quot;R1C1&quot;).

To create and run this macro:

 Enter the following macro on a macro sheet:

A1: SelectAll

A2: =SELECT(&quot;RC&quot;)

A3: =GET.CELL(1)

A4: =SELECT.LAST.CELL

A5: =GET.CELL(1)

A6: =SELECT(REFTEXT(INDIRECT(A3))&&quot;:&quot;& REFTEXT(INDIRECT(A5)))

A7: =RETURN

 Select cell A1 and choose Define Name from the Formula menu. The name SelectAll should show up in the Name box in the Define Name dialog box.

If not, you already have a name defined as SelectAll, so choose a different name for this macro and enter it in the Name box. In the Define Name dialog box, select the Command option. If you like, you can enter a shortcut key for this macro by selecting the Key: Ctrl+ box and typing the character you choose. In the Define Name dialog box, choose the OK button. To run your macro, choose Run from the Macro menu and select your macro name from the list, or, if you defined a shortcut key, press CTRL+ (use CONTROL on the Macintosh).</li></ol>

<div class="references_section">