|
楼主 |
发表于 2019-7-4 11:48
|
显示全部楼层
都是因为下面的程序老是出问题,但我找不原因,能否帮忙看看?
''去重 group用法
Sub MySum1()
Dim cnn As Object, sql$, i%
Set cnn = CreateObject("ADODB.Connection")
If Application.Version < 12 Then
cnn.Open "Provider=Microsoft.jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
Else
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
End If
'''求和列
sql = "select 标题1,sum(标题2) from [Sheet1$a1:H10] group by 标题1"
Cells(Rows.Count, "A").End(xlUp).Offset(1).CopyFromRecordset cnn.Execute(sql)
sql = "select 标题3,标题4,标题5,标题6,标题7,标题8 from [Sheet1$a1:H10] where 标题8 IN ('main') GROUP BY 标题1"
Cells(Rows.Count, "C").End(xlUp).Offset(1).CopyFromRecordset cnn.Execute(sql)
cnn.Close
Set cnn = Nothing
End Sub |
|