排序值的範圍。
運算式
。
排序
(
Key1
、
Order1
、
Key2
、
Type
、
Order2
、
Key3
、
Order3
、
Header
、
OrderCustom
、
MatchCase
、
Orientation
、
SortMethod
、
DataOption1
、
DataOption2
、
DataOption3
)
expression
代表
Range
物件的變數。
必要/選用
Variant
指定要在樞紐分析表中排序的專案類型。 指定
xLSortLabels
以依據樞紐分析表範圍之 [資料列/資料行標籤] 區域中之
experession
Range
的目標標籤排序,或在
Key1
另外以使用 R1C1 標記法之 Values 或 Sub/Grand Totals 區域中的儲存格為目標時排序
xLSortValues
。
Order2
XlSortOrder
決定
Key2
中所指定值的排序次序。
Variant
第三個排序欄位;無法在排序樞紐分析表時使用。
Order3
XlSortOrder
決定在
Key3
中所指定值的順序排序。
XlYesNoGuess
指定第一列是否包含標題資訊。
xlNo
是預設值,若要 Excel 試著判斷標題,請指定
xlGuess
。
OrderCustom
Variant
指定自訂排序順序清單中以一起始的整數位移。
MatchCase
Variant
設定為
True
以執行區分大小寫的排序,
False
則執行不區分大小寫的排序;無法與樞紐分析表搭配使用。
Orientation
XlSortOrientation
指定是否應以列 (預設值) 或欄進行排序。 將
xlSortColumns
值設定為 1 以依資料行排序。 將
xlSortRows
值設定為 2 以依資料列排序 (這是預設值) 。
SortMethod
XlSortMethod
指定排序方向。
DataOption1
XlSortDataOption
指定如何排序
Key1
中所指定範圍內的文字;不適用於樞紐分析表排序。
DataOption2
XlSortDataOption
指定如何排序
Key2
中所指定範圍內的文字;不適用於樞紐分析表排序。
DataOption3
XlSortDataOption
指定如何在
Key3
中指定的範圍內排序文字;不適用於樞紐分析表排序。
Variant
這個範例會使用
ColorIndex
屬性取得資料行 A 中儲存格的色彩值,然後使用該值依色彩排序範圍。
Sub ColorSort()
'Set up your variables and turn off screen updating.
Dim iCounter As Integer
Application.ScreenUpdating = False
'For each cell in column A, go through and place the color index value of the cell in column C.
For iCounter = 2 To 55
Cells(iCounter, 3) = _
Cells(iCounter, 1).Interior.ColorIndex
Next iCounter
'Sort the rows based on the data in column C
Range("C1") = "Index"
Columns("A:C").Sort key1:=Range("C2"), _
order1:=xlAscending, header:=xlYes
'Clear out the temporary sorting value in column C, and turn screen updating back on.
Columns(3).ClearContents
Application.ScreenUpdating = True
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。