質問するログイン新規登録

質問編集履歴

1

「a~zのアルファベット」は1例として記載しました。「特定の文字列」という表現の方がわかりやすいですね。わかりにくくすみませんでした。

2020/12/04 14:28

投稿

koyamashinji
koyamashinji

スコア45

title CHANGED
File without changes
body CHANGED
@@ -1,24 +1,24 @@
1
- 下記のコードは、cells(i, "B")の値がアルファベットa~zまの場合でないものを、行ごと削除するマクロです。
1
+ 下記のコードは、cells(i, "B")の値が「特定文字列」でないものを、行ごと削除するマクロです。
2
- 条件文`And Not`を以下のように26行分書くほかに、**もっと簡略な記述方法**があれば教えていただきたく。
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 = "a" And Not cellValue = "b" _
9
+ If Not cellValue = "文字列1" And Not cellValue = "文字列2" _
10
- And Not cellValue = "c" _
10
+ And Not cellValue = "文字列3" _
11
- And Not cellValue = "d" _
11
+ And Not cellValue = "文字列4" _
12
- And Not cellValue = "e" _
12
+ And Not cellValue = "文字列5" _
13
- And Not cellValue = "f" _
13
+ And Not cellValue = "文字列6" _
14
- And Not cellValue = "g" _
14
+ And Not cellValue = "文字列7" _
15
- And Not cellValue = "h" _
15
+ And Not cellValue = "文字列8" _
16
16
                   ・
17
17
                   ・
18
18
                  (省略)
19
19
                   ・
20
20
                   ・
21
- And Not cellValue= "z" Then
21
+ And Not cellValue= "文字列20" Then
22
22
  Cells(i, "B").EntireRow.Delete
23
23
  End If
24
24
  Next i