データの並べ替え(Sort):Excel VBA入門 |
スポンサードリンク | |
メンバ | 値 | 説明 |
xlAscending | 1 | 既定値。昇順に並べ替えます |
xlDescending | 2 | 降順に並べ替えます |
メンバ | 値 | 説明 |
xlGuess | 0 | 先頭行が見出しであるかどうかをExcelに自動で判断させます |
xlNo | 2 | 既定値。範囲全体が並べ替えの対象となります |
xlYes | 1 | 先頭行をタイトル行と見なし、それ以外の範囲が並べ替えられます |
メンバ | 値 | 説明 |
True | 1 | 大文字と小文字を区別して並べ替えを行います |
False | 0 | 大文字と小文字を区別しないで並べ替えを行います |
メンバ | 値 | 説明 |
xlTopToBottom | 1 | 既定値。行方向の並べ替えになります |
xlLeftToRight | 2 | 列方向の並べ替えになります |
メンバ | 値 | 説明 |
xlSortColumns | 1 | 列単位で並べ替えます。←行方向の並べ替えになります |
xlSortRows | 2 | 既定値。行単位で並べ替えます←列方向の並べ替えになります |
メンバ | 値 | 説明 |
xlPinYin | 1 | 既定値。ふりがなを使う。 |
xlStroke | 2 | ふりがなを使わない。文字コード順。 |
メンバ | 値 | 説明 |
xlSortNormal | 0 | 既定値。数値データとテキスト データを別々に並べ替えます |
xlSortTextAsNumbers | 1 | テキストを数値データとして並べ替えます |
出席番号 | 氏名 | 国語 | 算数 | 理科 | 社会 | 合計 | 順位 | 評価 |
1001 | 佐藤 | 20 | 51 | 48 | 46 | 165 | 9 | 不可 |
1002 | 鈴木 | 56 | 64 | 67 | 59 | 246 | 5 | 良 |
1003 | 高橋 | 89 | 92 | 97 | 81 | 359 | 1 | 優 |
1004 | 田中 | 71 | 78 | 75 | 85 | 309 | 4 | 良 |
1005 | 渡辺 | 25 | 34 | 45 | 54 | 158 | 10 | 不可 |
1006 | 伊藤 | 48 | 56 | 42 | 52 | 198 | 7 | 可 |
1007 | 山本 | 92 | 88 | 84 | 76 | 340 | 2 | 優 |
1008 | 中村 | 84 | 89 | 76 | 84 | 333 | 3 | 良 |
1009 | 小林 | 61 | 59 | 65 | 54 | 239 | 6 | 可 |
1010 | 加藤 | 34 | 47 | 38 | 49 | 168 | 8 | 可 |
Sub sort1() Range("A1:I11").Sort _ Key1:=Range("B2"), _ Order1:=xlAscending, _ Header:=xlGuess, _ OrderCustom:=1, _ MatchCase:=False, _ Orientation:=xlTopToBottom, _ SortMethod:=xlPinYin, _ DataOption1:=xlSortTextAsNumbers 'Excel2002より前のバージョンでは不要 End Sub |
Sub sort2() Range("A1:I11").Sort _ Key1:=Range("G1"), _ Order1:=xlDescending, _ Header:=xlYes, _ Orientation:=xlTopToBottom End Sub |
Sub sort3() Dim lRow As Long Dim lCol As Long Dim myRng As Range With Worksheets("Sheet1") lRow = Cells(Rows.Count, 1).End(xlUp).Row lCol = Cells(1, Columns.Count).End(xlToLeft).Column Set myRng = .Range(Cells(1, 1), Cells(lRow, lCol)) myRng.Sort _ Key1:=.Range("G1"), _ Order1:=xlDescending, _ Header:=xlYes, _ Orientation:=xlTopToBottom End With End Sub |
スポンサードリンク
PageViewCounter
Since2006/2/27