'指定した特定の文字のカウント
Sub Count()
'Sheet設定
Dim Ws1 As Worksheet
Set Ws1 = Worksheets("Sheet1")
'最終行の取得
Dim Cend As Long
Cend = Ws1.Range("A1048576").End(xlUp).Row
'検索ワード
Dim Keyworld As String
ReDim KeyWord(1)
KeyWord(0) = "テスト0"
KeyWord(1) = "テスト1"
'変数定義
Dim i As Long
Dim SeekWord As String
Dim KeyWordTest0 As Long
Dim KeyWordTest1 As Long
Application.ScreenUpdating = False
'A列の値を取得
For i = 1 To Cend
SeekWord = Ws1.Range("A" & i).Value
'A列のKeyWordとなる文字を検索
If InStr(SeekWord, KeyWord(0)) > 0 Then
'件数のカウント
KeyWordTest0 = KeyWordTest0 + 1
Ws1.Range("B1").Value = KeyWordTest0
ElseIf InStr(SeekWord, KeyWord(1)) > 0 Then
KeyWordTest1 = KeyWordTest1 + 1
Ws1.Range("B2").Value = KeyWordTest1
End If
Next
Application.ScreenUpdating = True
End Sub
2023年12月17日