回答編集履歴

1

コードの改善

2017/08/19 18:15

投稿

hatena19
hatena19

スコア33742

test CHANGED
@@ -16,27 +16,29 @@
16
16
 
17
17
  For i = 1 To .Cells(1, 1).CurrentRegion.Columns.Count
18
18
 
19
- If .Cells(3, i) <> "" Then
19
+ Set R = .Cells(3, i)
20
20
 
21
- .Cells(3, i) = .Cells(1, i).MergeArea(1, 1) & "/" & _
21
+ If R <> "" Then
22
22
 
23
- .Cells(2, i).MergeArea(1, 1) & "/" & _
23
+ R = R.Offset(-2).MergeArea(1, 1) & "/" & _
24
24
 
25
- .Cells(3, i)
25
+ R.Offset(-1).MergeArea(1, 1) & "/" & _
26
26
 
27
- ElseIf .Cells(3, i).MergeArea.Rows.Count = 2 Then
27
+ R
28
28
 
29
- .Cells(3, i).UnMerge
29
+ ElseIf R.MergeArea.Rows.Count = 2 Then
30
30
 
31
- .Cells(3, i) = .Cells(1, i).MergeArea(1, 1) & "/" & _
31
+ R.UnMerge
32
32
 
33
- .Cells(2, i)
33
+ R = R.Offset(-2).MergeArea(1, 1) & "/" & _
34
34
 
35
- ElseIf .Cells(3, i).MergeArea.Rows.Count = 3 Then
35
+ R.Offset(-1)
36
36
 
37
- .Cells(3, i).UnMerge
37
+ ElseIf R.MergeArea.Rows.Count = 3 Then
38
38
 
39
+ R.UnMerge
40
+
39
- .Cells(3, i) = .Cells(1, i).MergeArea(1, 1)
41
+ R = R.Offset(-2).MergeArea(1, 1)
40
42
 
41
43
  End If
42
44