|
- Function 多列多条件汇总2()
- Dim lngRows As Long
- Dim Conn As Object, Rst As Object, strPath As String
- Dim strConn As String, strSQL As String
- Dim rg As Range
- lngRows = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
- Set rg = Sheet1.Range("G2")
- Set Conn = CreateObject("ADODB.Connection")
- Set Rst = CreateObject("ADODB.Recordset")
- strPath = ThisWorkbook.FullName
- Select Case Application.Version * 1
- Case Is <= 11
- strConn = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=excel 8.0;Data source=" & strPath
- Case Is >= 12
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strPath & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
- End Select
- Conn.Open strConn
- '''''''''''''''''''''''''''''''''
- strSQL = "SELECT 单据编号,物料长代码,SUM(申请数) AS 申请合计,SUM(实发数) AS 实发合计 " & _
- "FROM [生产领料序时簿$A1:D" & lngRows & "] " & _
- "Group By 单据编号,物料长代码 "
- Rst.Open strSQL, Conn, 3, 1
- Sheet1.Range("G:J").ClearContents
- Sheet1.Range("G1:J1") = Array("单据编号", "物料长代码", "申请数", "实发数")
- rg.CopyFromRecordset Rst
- Set Rst = Nothing
- Set Conn = Nothing
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|