|
- Sub summery()
- Dim conn As Object, rst As Object, strSQL$, i&, PathStr$, sht As Worksheet
- Set conn = CreateObject("ADODB.Connection")
- Set rst = CreateObject("ADODB.Recordset")
- PathStr = ThisWorkbook.FullName '路径
- Select Case Application.Version * 1
- Case Is <= 11
- conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & PathStr & ";Extended Properties='Excel 8.0;HDR=YES;IMEX=0'"
- Case Is >= 12
- conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PathStr & ";Extended Properties='Excel 12.0;HDR=YES;IMEX=0'"
- End Select
- strSQL = "SELECT 品项编码,max(CDate(Format(单据日期, '####/##/##'))) as 日期 FROM [明细$] group by 品项编码"
- strSQL = "select a.品项编码,b.品项名称,b.规格,b.单位,a.日期,b.不含税单价 from (" & strSQL & ")a left join [明细$]b on b.品项编码=a.品项编码 and CDate(Format(b.单据日期, '####/##/##'))=a.日期"
- rst.Open strSQL, conn, 1, 3
- '替换为对结果的处理-------------------------------------
- With Worksheets("统计")
- .Range("a2").CopyFromRecordset rst
- End With
- conn.Close: Set conn = Nothing: Set rst = Nothing
- End Sub
复制代码 |
|