質問編集履歴

2

2020/05/19 11:38

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -7,6 +7,18 @@
7
7
  他に方法はないでしょうか。
8
8
 
9
9
  ちなみに、 (xlToLeft)しなければ動きは早いです。
10
+
11
+
12
+
13
+ F g1|Fg2 |Fg3 |Fg4
14
+
15
+ aaa|bbb|空白 |ccc
16
+
17
+ aaa|aaa|空白 |空白
18
+
19
+ ccc|空白 |ccc|bbb
20
+
21
+ aaa|ccc|bbb|ddd
10
22
 
11
23
 
12
24
 

1

2020/05/19 11:38

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -14,21 +14,17 @@
14
14
 
15
15
  ```
16
16
 
17
- Dim i, j As Long
17
+ Sub sample()
18
18
 
19
+ Dim i As Long, j As Long
19
20
 
21
+ For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
20
22
 
21
- For i = 2 To Cells(Rows.Count, 1).End(xlUp)
23
+ For j = 4 To 1 Step -1
22
24
 
23
- For j = 1 To 4
24
-
25
-
26
-
27
- If Cells(i, j) = WorksheetFunction.CountIf(Range(Cells(i, 1), Cells(i, 4)), Cells(i, j)) > 1 Then
25
+ If WorksheetFunction.CountIf(Range(Cells(i, 1), Cells(i, 4)), Cells(i, j)) > 1 Or Cells(i, j) = "" Then
28
26
 
29
27
  Cells(i, j).Delete (xlToLeft)
30
-
31
-
32
28
 
33
29
  End If
34
30
 
@@ -36,8 +32,6 @@
36
32
 
37
33
  Next i
38
34
 
39
-
40
-
41
35
  End Sub
42
36
 
43
37