Microsoft Office Tutorials and References
In Depth Information
19.3.43 Select Method
19.3.43 Select Method
This method selects the given range. Actually, the Select method applies to a whopping 81
different Excel objects. For the Range object, its syntax is:
Note that this method selects a range of cells, whereas the Activate method activates a single cell.
19.3.44 ShrinkToFit Property
This property can be set to True to tell Excel to shrink the font size of all text in the range so that
the text fits the available column width. It also returns True if ShrinkToFit is set for all cells in
the range, False if it is turned off for all cells in the range, or Null if some cells have
ShrinkToFit turned on and others have ShrinkToFit turned off.
19.3.45 Sort Method
This method sorts a range or the current region when the specified range contains only one cell. It
can also be used to sort a pivot table. The syntax is:
RangeObject .Sort( Key1 , Order1 , Key2 , Type , Order2 , Key3 , Order3 , _
Header , OrderCustom , MatchCase , Orientation , SortMethod , _
IgnoreControlCharacters , IgnoreDiacritics , IgnoreKashida )
Sorting can take place based on up to three keys, denoted by Key1 , Key2 , and Key3 . These
parameters can be expressed as text (a range name) or a Range object. The corresponding Order
parameter can be set to one of the following values:
xlAscending = 1 ' Default
xlDescending = 2
The optional Type parameter is used only when sorting pivot tables.
The optional Header parameter specifies whether the first row contains headers, in which case
they are not included in the sort. The Header parameter can be one of the following values:
xlGuess = 0
xlYes = 1
xlNo = 2 ' Default
The optional OrderCustom parameter is an integer offset into the list of custom sort orders.
However, Microsoft seems not to have documented this further, so it seems best to simply omit
this argument, in which case it is assumed to be Normal (which sounds good).
The optional MatchCase parameter should be set to True to do a case-sensitive sort and False
(the default) to do a sort that is not case-sensitive. For instance, suppose that cell A1 contains the
text "AAA" and cell A2 contains the text "aaa." The code:
Range("A1:A2").Sort Key1:=Cells(1, 1), MatchCase:=True