質問編集履歴

1

ソースを変更してみました

2025/04/07 06:58

投稿

rena_168
rena_168

スコア73

test CHANGED
File without changes
test CHANGED
@@ -55,20 +55,35 @@
55
55
 
56
56
  ```VBA
57
57
  Sub Workbook_Open()
58
+ Dim searchValue As String
58
- Dim sh As Worksheet
59
+ Dim currentSheet As Worksheet
59
- Dim FoundCell As Range
60
+ Dim cell As Range
61
+ Dim hitCount As Integer
60
- Dim シートNo As Long
62
+ Dim found As Boolean
61
-
63
+
62
- For Each sh In Worksheets
64
+ ' ユーザーフォームで検索語を入力する
63
- Set FoundCell = sh.Cells.Find(What:="2025/3/23 0:00:00", LookAt:=xlWhole)
64
- If Not FoundCell Is Nothing Then
65
- MsgBox sh.Name & "2025/3/23 0:00:00があります"
65
+ searchValue = InputBox("2025/3/23 0:00:00")
66
+
67
+ ' 全てのワークシートを検索する
68
+ For Each currentSheet In ActiveWorkbook.Worksheets
69
+ ' C8からC1800の範囲を検索する
70
+ For Each cell In currentSheet.Range("A2:C8")
71
+ ' セルの値に検索語が含まれているかチェックする
72
+ If InStr(1, cell.Value, searchValue, vbTextCompare) > 0 Then
73
+ hitCount = hitCount + 1
74
+ ' ヒットした場合はセルをアクティブにする
75
+ currentSheet.Activate
76
+ cell.Activate
66
- Exit Sub
77
+ found = True
67
- End If
78
+ End If
68
- Next
79
+ Next cell
69
- If FoundCell Is Nothing Then MsgBox "2025/3/23 0:00:00はありません"
80
+ Next currentSheet
81
+
70
- Set FoundCell = Nothing
82
+ If found = False Then
83
+ MsgBox "検索語が見つかりませんでした。"
71
- Set sh = Nothing
84
+ ElseIf hitCount >= 2 Then
85
+ MsgBox hitCount & "件のヒットがありました。"
86
+ End If
72
87
  End Sub
73
88
  ```
74
89