|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
按月份汇总.rar
(9.11 KB, 下载次数: 73)
Sub 按月汇总()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
conn.Open
If conn.State = adStateOpen Then
sSql = "Select distinct 客户 From [销售记录$A1:C65536] where 合计 > 1"
Cells(2, 1).CopyFromRecordset conn.Execute(sSql)
conn.Close
End If
Set conn = Nothing
For i = 1 To 12
Dim AdoCn As New ADODB.Connection, Rst As New ADODB.Recordset
AdoCn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=Yes;';Data Source=" & ThisWorkbook.FullName
Rst.Open "Select Cnt From [月份汇总$a1:a100] As A Left Join (Select 客户,Sum(合计) As Cnt From [销售记录$A1:C65536] where 日期 Like'2011-" & i & "%'Group By 客户) B On a.[客户]=b.[客户]", AdoCn
Cells(2, i + 1).CopyFromRecordset Rst: Rst.Close
AdoCn.Close: Set Rst = Nothing: Set AdoCn = Nothing
Next i
End Sub |
|