回答編集履歴

1

コード追加

2021/08/26 05:12

投稿

hatena19
hatena19

スコア34064

test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  Sub delCol3gyoumeNai()
12
12
 
13
- Dim i
13
+ Dim i As Long
14
14
 
15
15
  Dim MaxCol As Long
16
16
 
@@ -26,7 +26,57 @@
26
26
 
27
27
  Next
28
28
 
29
+ End Sub
29
30
 
31
+ ```
32
+
33
+
34
+
35
+ 別案
36
+
37
+ ---
38
+
39
+
40
+
41
+ Unionで複数列を纏めて、一気に削除する。
42
+
43
+
44
+
45
+ ```vba
46
+
47
+ Sub delCol3gyoumeNai1()
48
+
49
+ Dim i As Long
50
+
51
+ Dim MaxCol As Long
52
+
53
+ Dim r As Range
54
+
55
+
56
+
57
+ MaxCol = Cells(3, Columns.Count).End(xlToLeft).Column
58
+
59
+ For i = 1 To MaxCol
60
+
61
+ If Cells(3, i).Value = "" Then
62
+
63
+ If r Is Nothing Then
64
+
65
+ Set r = Columns(i)
66
+
67
+ Else
68
+
69
+ Set r = Union(r, Columns(i))
70
+
71
+ End If
72
+
73
+ End If
74
+
75
+ Next
76
+
77
+
78
+
79
+ r.Delete
30
80
 
31
81
  End Sub
32
82