|
Sub 筛选()
Dim R, C
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("明细账")
R = sh.Range("A65536").End(xlUp).Row
C = sh.[J1] '选车牌
If R > 2 Then sh.Range("A3:I" & R).Clear
On Error Resume Next
Dim CN As Object, Sql As String
Set CN = CreateObject("ADODB.Connection")
CN.Open "Provider = Microsoft.Jet.Oledb.4.0;Extended Properties =Excel 8.0;Data Source =" & ThisWorkbook.FullName
Sql = "select r.日期,r.月份,r.单据编号,r.车牌号,r.大类,r.摘要,r.支出,r.经手人,r.备注 from [日记账$] r where r.车牌号=" & C & " order by r.日期"
sh.Range("A3").CopyFromRecordset CN.Execute(Sql)
CN.Close
Set CN = Nothing
End Sub
|
|