teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コード追記

2018/05/19 00:46

投稿

hatena19
hatena19

スコア34367

answer CHANGED
@@ -4,8 +4,24 @@
4
4
  'ユーザー定義での並び替え
5
5
  Application.AddCustomList ListArray:=Array("A","B","C", 中略 ,"B1","B2","B3")
6
6
  ```
7
- Split関数を使った方
7
+ Split関数を使った方が記述が楽です。
8
8
  ```VBA
9
9
  'ユーザー定義での並び替え
10
10
  Application.AddCustomList ListArray:=Split("A,B,C, 中略 ,B1,B2,B3",",")
11
- ```
11
+ ```
12
+
13
+ Excel2007以降なら、Sortオプジェクトを使った方がいいかも。
14
+
15
+ ```vba
16
+ With Worksheets("Sheet1").Sort
17
+ .SortFields.Clear
18
+ .SortFields.Add Key:=Range("J1"), _
19
+ CustomOrder:="A,B,C, 中略 ,B1,B2,B3"
20
+ .SetRange Range("A:W")
21
+ .Header = xlGuess
22
+ .Orientation = xlTopToBottom
23
+ .Apply
24
+ End With
25
+ ```
26
+ 参考リンク
27
+ [Office TANAKA - Excel VBA Tips[Excel 2007のSortオブジェクト]](http://officetanaka.net/excel/vba/tips/tips148.htm)