24/07/25 17:49:40のコードは間違っていました。失礼しました。
以下に訂正します。
Sub matome()
Dim i As Long
Dim lRow As Long, lCol As Long, lRow2 As Long
Dim rng As Range, rng2 As Range
Dim Date1
Application.ScreenUpdating = False
Date1 = InputBox(prompt:=" 検索したい日付を書いてください。(例2024/7/26) ")
Worksheets(1).Cells.ClearContents
Worksheets(2).Range("1:1").Copy Worksheets(1).Range("A1")
For i = 2 To Worksheets.Count
With Worksheets(i)
If .AutoFilter Is Nothing Then .AutoFilterMode = False '★
lRow = .Cells(Rows.Count, 1).End(xlUp).Row
lCol = .Cells(1, Columns.Count).End(xlToLeft).Column
Set rng = .Range(.Cells(1, 1), .Cells(lRow, lCol))
Set rng2 = .Range(.Cells(2, 1), .Cells(lRow, lCol))
If lRow >= 2 Then
lRow2 = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row + 1
rng.AutoFilter field:=5, Criteria1:=Date1
If Intersect(rng, .Columns("A")).SpecialCells(xlCellTypeVisible) _
.Count >= 2 Then
rng2.Copy Worksheets(1).Cells(lRow2, 1)
End If
.AutoFilterMode = False
End If
End With
Next i
Worksheets(1).Activate
Range("A1").Select
Application.ScreenUpdating = True
End Sub