回答編集履歴
1
コード修正
test
CHANGED
@@ -6,13 +6,9 @@
|
|
6
6
|
|
7
7
|
Sub 昇順()
|
8
8
|
|
9
|
-
Application.ScreenUpdating = False
|
10
|
-
|
11
|
-
|
12
|
-
|
13
9
|
Dim ws As Worksheet
|
14
10
|
|
15
|
-
Set ws = Worksheets("Sheet
|
11
|
+
Set ws = Worksheets("Sheet1")
|
16
12
|
|
17
13
|
|
18
14
|
|
@@ -20,26 +16,42 @@
|
|
20
16
|
|
21
17
|
Set rng = ws.Range("A1").CurrentRegion 'データ範囲取得
|
22
18
|
|
19
|
+
|
20
|
+
|
21
|
+
'CustomOrder用文字列生成
|
22
|
+
|
23
|
+
Dim c As Range, CtmOrd As String
|
24
|
+
|
25
|
+
For Each c In rng.Columns(1).Cells
|
26
|
+
|
27
|
+
If InStr(CtmOrd & ",", "," & c.Value & ",") < 1 Then
|
28
|
+
|
29
|
+
CtmOrd = CtmOrd & "," & c.Value
|
30
|
+
|
31
|
+
End If
|
32
|
+
|
33
|
+
Next
|
34
|
+
|
35
|
+
CtmOrd = Mid(CtmOrd, 2)
|
36
|
+
|
23
37
|
|
24
38
|
|
25
39
|
With ws.Sort
|
26
40
|
|
27
41
|
.SortFields.Clear
|
28
42
|
|
29
|
-
.SortFields.Add
|
43
|
+
.SortFields.Add Key:=rng.Columns(1), CustomOrder:=CVar(CtmOrd)
|
30
44
|
|
31
|
-
.SortFields.Add
|
45
|
+
.SortFields.Add Key:=rng.Columns(4)
|
32
46
|
|
33
47
|
.SetRange rng
|
48
|
+
|
49
|
+
.Header = xlYes
|
34
50
|
|
35
51
|
.Apply
|
36
52
|
|
37
53
|
End With
|
38
54
|
|
39
|
-
|
40
|
-
|
41
|
-
Application.ScreenUpdating = True
|
42
|
-
|
43
55
|
End Sub
|
44
56
|
|
45
57
|
```
|