Sub LoopTwoColumns()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Integer
' 设置要操作的工作表
Set ws = ThisWorkbook.Worksheets("Sheet4")
' 获取第一个列数据的最后一行
lastRow = ws.Cells(Rows.count, 1).End(xlUp).row
' 循环遍历列数据
For i = 1 To lastRow
' 第一列数据
Dim value1 As Date
value1 = ws.Cells(i, 1).Value
' 第二列数据
Dim value2 As Date
value2 = ws.Cells(i, 2).Value
' 进行你需要的操作,这里只是打印到Immediate窗口
MsgBox "Value1: " & value1 & ", Value2: " & value2
startDate = value1
endDate = value2
' 要操作表格sheet3
' 范围设置为日期所在的列
Dim ws3 As Worksheet
Set ws3 = ThisWorkbook.Worksheets("Sheet3")
Set dateColumn = ws3.Range("A:A")
' 重置记录计数器为零
recordCount = 0
' 使用循环遍历每个单元格,并检查是否在日期范围内
For Each cell In dateColumn
If cell.Value >= startDate And cell.Value <= endDate Then
recordCount = recordCount + 1
End If
Next cell
ws.Range("C" & i).Value = recordCount
Next i
End Sub