回答編集履歴
2
追加
answer
CHANGED
@@ -119,3 +119,60 @@
|
|
119
119
|
Sub 空白行詰(GStart As Integer, GEnd As Integer, ColStart As Integer, ColEnd As Integer)
|
120
120
|
End Sub
|
121
121
|
```
|
122
|
+
|
123
|
+
追記:RemoveDuplicatesを使って書き換え。すべての機能実現
|
124
|
+
---
|
125
|
+
置換前
|
126
|
+
||A列|B列|C列|D列|E列|F列|E列|
|
127
|
+
|:--:|:--:|:--:|:--:|:--:|:--:|:--:|:--:|
|
128
|
+
|1行|A|○|○|○|○|○|○|
|
129
|
+
|2行|A|△|△|△|×|×|×|
|
130
|
+
|3行|A|○|○|○|×|×|×|
|
131
|
+
|4行|B|○|○|○|○|○|○|
|
132
|
+
|5行|C|○|○|○|○|○|○|
|
133
|
+
|
134
|
+
```VBA
|
135
|
+
Option Explicit
|
136
|
+
|
137
|
+
Sub test2()
|
138
|
+
Dim GStart As Integer
|
139
|
+
Dim GEnd As Integer
|
140
|
+
Dim RCount As Integer
|
141
|
+
Dim GName As String
|
142
|
+
|
143
|
+
RCount = 1
|
144
|
+
Do While True
|
145
|
+
GName = ActiveSheet.Cells(RCount, 1).Value
|
146
|
+
If GName = "" Then
|
147
|
+
Exit Do
|
148
|
+
End If
|
149
|
+
|
150
|
+
GStart = RCount
|
151
|
+
GEnd = グループ終端(GStart)
|
152
|
+
|
153
|
+
ActiveSheet.Range(ActiveSheet.Cells(GStart, 2), ActiveSheet.Cells(GEnd, 4)).RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlNo
|
154
|
+
ActiveSheet.Range(ActiveSheet.Cells(GStart, 5), ActiveSheet.Cells(GEnd, 7)).RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlNo
|
155
|
+
|
156
|
+
RCount = GEnd + 1
|
157
|
+
Loop
|
158
|
+
End Sub
|
159
|
+
|
160
|
+
Function グループ終端(GStart As Integer) As Integer
|
161
|
+
Dim RCount As Integer
|
162
|
+
Dim GName As String
|
163
|
+
|
164
|
+
RCount = GStart
|
165
|
+
GName = ActiveSheet.Cells(RCount, 1).Value
|
166
|
+
If GName = "" Then
|
167
|
+
グループ終端 = 0
|
168
|
+
Else
|
169
|
+
Do While True
|
170
|
+
If (ActiveSheet.Cells(RCount, 1).Value = GName) And (ActiveSheet.Cells(RCount + 1, 1).Value <> GName) Then
|
171
|
+
グループ終端 = RCount
|
172
|
+
Exit Do
|
173
|
+
End If
|
174
|
+
RCount = RCount + 1
|
175
|
+
Loop
|
176
|
+
End If
|
177
|
+
End Function
|
178
|
+
```
|
1
追加
answer
CHANGED
@@ -6,4 +6,116 @@
|
|
6
6
|
|:--:|:--:|:--:|:--:|:--:|:--:|:--:|
|
7
7
|
|A|○|○|○|○|○|○|
|
8
8
|
|A|△|△|△|×|×|×|
|
9
|
-
|A|○|○|○|△|△|△|
|
9
|
+
|A|○|○|○|△|△|△|
|
10
|
+
|
11
|
+
追記
|
12
|
+
---
|
13
|
+
途中で力つきまして、空白行を詰める処置が入っていませんが
|
14
|
+
あとは頑張ってみてください。
|
15
|
+
ソースはかなりベタな感じですが、一応それ以外は動いています。
|
16
|
+
|
17
|
+
```VBA
|
18
|
+
Option Explicit
|
19
|
+
|
20
|
+
Sub test()
|
21
|
+
Dim GStart As Integer
|
22
|
+
Dim GEnd As Integer
|
23
|
+
Dim RCount As Integer
|
24
|
+
Dim GName As String
|
25
|
+
|
26
|
+
RCount = 1
|
27
|
+
Do While True
|
28
|
+
GName = ActiveSheet.Cells(RCount, 1).Value
|
29
|
+
If GName = "" Then
|
30
|
+
Exit Do
|
31
|
+
End If
|
32
|
+
|
33
|
+
GStart = RCount
|
34
|
+
GEnd = グループ終端(GStart)
|
35
|
+
|
36
|
+
重複削除 GStart, GEnd, 2, 4
|
37
|
+
重複削除 GStart, GEnd, 5, 7
|
38
|
+
空白行詰 GStart, GEnd, 2, 4
|
39
|
+
空白行詰 GStart, GEnd, 5, 7
|
40
|
+
|
41
|
+
RCount = GEnd + 1
|
42
|
+
Loop
|
43
|
+
End Sub
|
44
|
+
|
45
|
+
Function グループ終端(GStart As Integer) As Integer
|
46
|
+
Dim RCount As Integer
|
47
|
+
Dim GName As String
|
48
|
+
|
49
|
+
RCount = GStart
|
50
|
+
GName = ActiveSheet.Cells(RCount, 1).Value
|
51
|
+
If GName = "" Then
|
52
|
+
グループ終端 = 0
|
53
|
+
Else
|
54
|
+
Do While True
|
55
|
+
If (ActiveSheet.Cells(RCount, 1).Value = GName) And (ActiveSheet.Cells(RCount + 1, 1).Value <> GName) Then
|
56
|
+
グループ終端 = RCount
|
57
|
+
Exit Do
|
58
|
+
End If
|
59
|
+
RCount = RCount + 1
|
60
|
+
Loop
|
61
|
+
End If
|
62
|
+
End Function
|
63
|
+
|
64
|
+
Sub 重複削除(GStart As Integer, GEnd As Integer, ColStart As Integer, ColEnd As Integer)
|
65
|
+
Debug.Print "==========="
|
66
|
+
Dim i As Integer
|
67
|
+
Dim iEnd As Integer
|
68
|
+
Dim j As Integer
|
69
|
+
Dim jStart As Integer
|
70
|
+
Dim col As Integer
|
71
|
+
Dim 一致 As Boolean
|
72
|
+
|
73
|
+
iEnd = GEnd - 1
|
74
|
+
If iEnd = GStart Then
|
75
|
+
Exit Sub
|
76
|
+
End If
|
77
|
+
|
78
|
+
For i = GStart To iEnd
|
79
|
+
jStart = GStart + 1
|
80
|
+
If jStart > GEnd Then
|
81
|
+
Exit For
|
82
|
+
End If
|
83
|
+
|
84
|
+
一致 = True
|
85
|
+
For col = ColStart To ColEnd
|
86
|
+
If ActiveSheet.Cells(i, col).Value = "" Then
|
87
|
+
Else
|
88
|
+
一致 = False
|
89
|
+
Exit For
|
90
|
+
End If
|
91
|
+
Next col
|
92
|
+
If 一致 Then
|
93
|
+
GoTo tobashi
|
94
|
+
End If
|
95
|
+
|
96
|
+
For j = jStart To GEnd
|
97
|
+
If i = j Then
|
98
|
+
Else
|
99
|
+
Debug.Print i, j
|
100
|
+
一致 = True
|
101
|
+
For col = ColStart To ColEnd
|
102
|
+
If ActiveSheet.Cells(i, col).Value = ActiveSheet.Cells(j, col).Value Then
|
103
|
+
Else
|
104
|
+
一致 = False
|
105
|
+
Exit For
|
106
|
+
End If
|
107
|
+
Next col
|
108
|
+
If 一致 Then
|
109
|
+
For col = ColStart To ColEnd
|
110
|
+
ActiveSheet.Cells(j, col).Value = ""
|
111
|
+
Next col
|
112
|
+
End If
|
113
|
+
End If
|
114
|
+
Next j
|
115
|
+
tobashi:
|
116
|
+
Next i
|
117
|
+
End Sub
|
118
|
+
|
119
|
+
Sub 空白行詰(GStart As Integer, GEnd As Integer, ColStart As Integer, ColEnd As Integer)
|
120
|
+
End Sub
|
121
|
+
```
|