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

回答編集履歴

3

修正

2021/12/21 02:19

投稿

退会済みユーザー
answer CHANGED
@@ -14,7 +14,7 @@
14
14
  If .Test(Cells(i, 2)) Then
15
15
  Cells(i, 1) = Cells(i, 2)
16
16
  End If
17
- Next i
17
+ Next
18
18
  End With
19
19
  Set regexp = Nothing
20
20
  End Sub

2

サンプル追記

2021/12/21 02:19

投稿

退会済みユーザー
answer CHANGED
@@ -1,2 +1,23 @@
1
1
  【】で囲まれた値を抽出するだけであれば、正規表現を使うと処理がシンプルになりそうな気がします。
2
- [正規表現によるマッチング](http://officetanaka.net/excel/vba/tips/tips38.htm)
2
+ [正規表現によるマッチング](http://officetanaka.net/excel/vba/tips/tips38.htm)
3
+
4
+ 例えば、こんなコードで
5
+ ```ここに言語を入力
6
+ Private Sub CommandButton1_Click()
7
+ Dim regexp As Object
8
+ Dim i As Long
9
+ Set regexp = CreateObject("VBScript.RegExp")
10
+ With regexp
11
+ .Pattern = "^【.*】$"
12
+ .Global = True
13
+ For i = 1 To 5
14
+ If .Test(Cells(i, 2)) Then
15
+ Cells(i, 1) = Cells(i, 2)
16
+ End If
17
+ Next i
18
+ End With
19
+ Set regexp = Nothing
20
+ End Sub
21
+ ```
22
+ こうなります。
23
+ ![実行結果](68b22f866e7b7b06ec3cf6e30c26e28b.png)

1

追記

2021/12/21 02:17

投稿

退会済みユーザー
answer CHANGED
@@ -1,2 +1,2 @@
1
- 正規表現を使うと処理がシンプルになりそうな気がします。
1
+ 【】で囲まれた値を抽出するだけであれば、正規表現を使うと処理がシンプルになりそうな気がします。
2
2
  [正規表現によるマッチング](http://officetanaka.net/excel/vba/tips/tips38.htm)