|
Sub a()
Set cn = CreateObject("adodb.connection")
Set Rs = CreateObject("ADODB.RECORDSET")
cn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;EXTENDED PROPERTIES=EXCEL 8.0;DATA SOURCE=" & ThisWorkbook.FullName
Sql = "SELECT DISTINCT 姓名 FROM[多条件单列分类汇总$B1:L]":
Set Rs = cn.Execute(Sql)
Do Until Rs.EOF
Sheets("目标").[a1:e1] = Array("姓名", "学校", "类别", "数量", "合计")
n = Sheets("目标").Range("b65536").End(xlUp).Row
XM = Rs.fields(0)
n = Sheets("目标").Range("b65536").End(xlUp).Row
sqll = "select 姓名,学校,类别,数量 from [多条件单列分类汇总$B1:L] WHERE 姓名='" & XM & "'"
Sheets("目标").Range("a" & n + 1).CopyFromRecordset cn.Execute(sqll)
sqlll = "select sum(数量) from [多条件单列分类汇总$B1:L] WHERE 姓名='" & XM & "'"
Sheets("目标").Range("E" & n + 1).CopyFromRecordset cn.Execute(sqlll)
Rs.movenext
Loop
End Sub |
|