Sortオブジェクト

🟢 Excel VBA
投稿日: 2026年4月13日8:19
shSheet.Sort.SortFields.Clear
    shSheet.Sort.SortFields.Add2 Key:=Range(Cells(1, 2), Cells(10,2)), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With shSheet
        .SetRange Range(Cells(1, 1), Cells(10,10))
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
Sortオブジェクトはシートのプロパティに含まれるオブジェクト。
シートのSortオブジェクトを初期化してから開始。
キーの範囲を指定。
(フィールドコレクションで昇順・降順なども指定)

範囲やヘッダーを含むかどうかなどのパラメータを設定してから、
Applyメソッドで実行。

Header xlGuess 先頭をタイトルか自動判定
xlNo 先頭をタイトルとみなさない
xlYes 先頭をタイトルとみなす

MatchCase TRUE 大文字・小文字を区別する
FALSE 大文字・小文字を区別しない

Orientation xlSortRows 行(縦方向)の並び替え
xlSortColumn 列(横方向)の並び替え