Partager via


NamedRange.SortSpecial Method

Uses East Asian sorting methods to sort the NamedRange control. For example, Japanese sorts in the order of the Kana syllabary. For more information, see the parameters list.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Syntax

'Declaration
Function SortSpecial ( _
    SortMethod As XlSortMethod, _
    Key1 As Object, _
    Order1 As XlSortOrder, _
    Type As Object, _
    Key2 As Object, _
    Order2 As XlSortOrder, _
    Key3 As Object, _
    Order3 As XlSortOrder, _
    Header As XlYesNoGuess, _
    OrderCustom As Object, _
    MatchCase As Object, _
    Orientation As XlSortOrientation, _
    DataOption1 As XlSortDataOption, _
    DataOption2 As XlSortDataOption, _
    DataOption3 As XlSortDataOption _
) As Object
Object SortSpecial(
    XlSortMethod SortMethod,
    Object Key1,
    XlSortOrder Order1,
    Object Type,
    Object Key2,
    XlSortOrder Order2,
    Object Key3,
    XlSortOrder Order3,
    XlYesNoGuess Header,
    Object OrderCustom,
    Object MatchCase,
    XlSortOrientation Orientation,
    XlSortDataOption DataOption1,
    XlSortDataOption DataOption2,
    XlSortDataOption DataOption3
)

Parameters

  • SortMethod
    Type: Microsoft.Office.Interop.Excel.XlSortMethod

    The type of sort. Some of these constants may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.

    Can be one of the following XlSortMethod values:

    xlStroke. Sorting by the quantity of strokes in each character.

    xlPinYin (default). Phonetic Chinese sort order for characters.

  • Type
    Type: System.Object

    Specifies which elements are to be sorted. Use this argument only when sorting PivotTable reports.

  • Header
    Type: Microsoft.Office.Interop.Excel.XlYesNoGuess

    Specifies whether or not the first row contains headers. Cannot be used when sorting PivotTable reports.

    Can be one of the following XlYesNoGuess values:

    xlGuess. Lets Microsoft Office Excel determine whether there is a header, and to determine where it is, if there is one.

    xlNo (default). The entire range should be sorted.

    xlYes. The entire range should not be sorted.

  • OrderCustom
    Type: System.Object

    This argument is a one-based integer offset to the list of custom sort orders. If you omit OrderCustom, normal sort order is used.

  • MatchCase
    Type: System.Object

    true to do a case-sensitive sort; false to do a sort that is not case sensitive. Cannot be used when sorting PivotTable reports.

Return Value

Type: System.Object

Remarks

If no arguments are defined with this method, Microsoft Office Excel sorts the selection in ascending order.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Examples

The following code example uses the SortSpecial method to sort a NamedRange using Pin Yin (phonetic Chinese sort order for characters). To sort Chinese characters, this example assumes the user has Chinese language support for Microsoft Office Excel. Excel will default to sorting the NamedRange by value if the user does not have Chinese language support.

This example is for a document-level customization.

Private Sub SortSpecialNamedRange()
        Me.Range("A1").Value2 = 50
        Me.Range("A2").Value2 = 10
        Me.Range("A3").Value2 = 20
        Me.Range("A4").Value2 = 30
        Me.Range("A5").Value2 = 40

        Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
            = Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
            "namedRange1")

        namedRange1.SortSpecial(Excel.XlSortMethod.xlPinYin, _
            Me.Range("A1", "A5"), Excel.XlSortOrder.xlAscending, , , _
            Excel.XlSortOrder.xlAscending, , _
            Excel.XlSortOrder.xlAscending, _
            Excel.XlYesNoGuess.xlNo, , , _
            Excel.XlSortOrientation.xlSortColumns, _
            Excel.XlSortDataOption.xlSortNormal, _
            Excel.XlSortDataOption.xlSortNormal, _
            Excel.XlSortDataOption.xlSortNormal)
    End Sub
private void SortSpecialNamedRange()
{
    this.Range["A1"].Value2 = 50;
    this.Range["A2"].Value2 = 10;
    this.Range["A3"].Value2 = 20;
    this.Range["A4"].Value2 = 30;
    this.Range["A5"].Value2 = 40;

    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");

    namedRange1.SortSpecial(Excel.XlSortMethod.xlPinYin,
        this.Range["A1", "A5"], Excel.XlSortOrder.xlAscending,
        missing, missing, Excel.XlSortOrder.xlAscending,
        missing, Excel.XlSortOrder.xlAscending,
        Excel.XlYesNoGuess.xlNo, missing, missing,
        Excel.XlSortOrientation.xlSortColumns,
        Excel.XlSortDataOption.xlSortNormal,
        Excel.XlSortDataOption.xlSortNormal,
        Excel.XlSortDataOption.xlSortNormal);

}

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace