|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
你试试
Sub 查询()
Set cnn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
For i = 2 To Range("b65536").End(xlUp).Row
s1 = Cells(i, 2)
s2 = CDate(Cells(i, 3))
s3 = Cells(i, 4)
Sql = "select * from [基表$] where 车牌号='" & s1 & "' and " _
& "路线 like ' %s3% ' and #" & s2 & "# between cdate(left(通行时间,instr([通行时间],'-')-1)) " _
& "and cdate(right(通行时间,instr([通行时间],'-')-1))"
rs.Open Sql, cnn, 1, 3
If rs.RecordCount = 0 Then
Range(Cells(i, 1), Cells(i, 4)).Interior.ColorIndex = 3
End If
rs.Close
Next i
End Sub
这个怎么不对,应该怎样修改 |
|
|