求助ADO高手一个在Excel中用语句sql汇总的问题
请教各位老师以下代码能在Excel中分类汇总,我用VB6封装成DLL后,汇总功能不运行,烦劳各位老师帮忙指点,谢谢Sub 材料汇总()
Dim lr&
Dim sql$, x
Application.ScreenUpdating = False
Set x = CreateObject("ADODB.Connection")
x.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=yes;imex=1';Data Source=" & ThisWorkbook.FullName
sql = "select 材料名称,型号规格,材质,sum(总重kg) from [材料清单$c2:v" & Sheets("材料清单").[c65536].End(xlUp).Row & "] group by 材料名称,型号规格,材质 "
With Sheets("材料汇总")
lr = .Cells(65535, 2).End(xlUp).Row
If lr > 3 Then .Rows("4:" & lr).Formula = ""
.[b4].CopyFromRecordset x.Execute(sql)
lr = .Cells(65535, 2).End(xlUp).Row
If lr > 3 Then .[a4] = 1
If lr > 4 Then .[a5] = 2
If lr > 5 Then .Range("A4:A5").AutoFill Range("A4:A" & lr)
End With
x.Close: Set x = Nothing
Application.ScreenUpdating = True
End Sub
这个是附件
汇总.rar
(42.77 KB)