質問編集履歴
1
「a~zのアルファベット」は1例として記載しました。「特定の文字列」という表現の方がわかりやすいですね。わかりにくくすみませんでした。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
下記のコードは、cells(i, "B")の値が
|
|
1
|
+
下記のコードは、cells(i, "B")の値が「特定の文字列」でないものを、行ごと削除するマクロです。
|
|
2
|
-
条件文`And Not`を以下のように
|
|
2
|
+
条件文`And Not`を以下のように条件数の分だけ書くほかに、**もっと簡略な記述方法**があれば教えていただきたく。
|
|
3
3
|
是非よろしくお願いします。
|
|
4
4
|
```
|
|
5
5
|
(省略)
|
|
6
6
|
For i = LastRow To 2 Step -1
|
|
7
7
|
Dim cellValue As String
|
|
8
8
|
cellValue = Cells(i, "B").Value
|
|
9
|
-
If Not cellValue = "
|
|
9
|
+
If Not cellValue = "文字列1" And Not cellValue = "文字列2" _
|
|
10
|
-
And Not cellValue = "
|
|
10
|
+
And Not cellValue = "文字列3" _
|
|
11
|
-
And Not cellValue = "
|
|
11
|
+
And Not cellValue = "文字列4" _
|
|
12
|
-
And Not cellValue = "
|
|
12
|
+
And Not cellValue = "文字列5" _
|
|
13
|
-
And Not cellValue = "
|
|
13
|
+
And Not cellValue = "文字列6" _
|
|
14
|
-
And Not cellValue = "
|
|
14
|
+
And Not cellValue = "文字列7" _
|
|
15
|
-
And Not cellValue = "
|
|
15
|
+
And Not cellValue = "文字列8" _
|
|
16
16
|
・
|
|
17
17
|
・
|
|
18
18
|
(省略)
|
|
19
19
|
・
|
|
20
20
|
・
|
|
21
|
-
And Not cellValue= "
|
|
21
|
+
And Not cellValue= "文字列20" Then
|
|
22
22
|
Cells(i, "B").EntireRow.Delete
|
|
23
23
|
End If
|
|
24
24
|
Next i
|