|
Sub Limonet2()
Dim Cn As Object, StrSQL$, Arr As Variant, Cri$
Set Cn = CreateObject("adodb.connection")
Cn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.FullName
Arr = Cn.Execute("select distinct 购货方名称 from [发票数据$A:N] where 开票日期<=#2021-12-31#").getrows
Cri = "'" & Join(WorksheetFunction.Transpose(WorksheetFunction.Transpose(Arr)), "','") & "'"
StrSQL = "select month(开票日期) as 分类,购货方名称,购货方社会统一信用代码 from [发票数据$A:N] where 购货方名称 not in(" & Cri & ") group by month(开票日期),购货方名称,购货方社会统一信用代码 having sum(发票金额)>=1000" '搁置
StrSQL = "select first(分类)&'月新客户',购货方名称,购货方社会统一信用代码 from (" & StrSQL & ") group by 购货方名称,购货方社会统一信用代码"
Range("A7").CopyFromRecordset Cn.Execute(StrSQL)
Cn.Close
Set Cn = Nothing
End Sub
|
|