|
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[源数据$A2:E]": sqll = "SELECT DISTINCT 供应商 FROM[源数据$A2:E]"
Set rs = cn.Execute(Sql): Set Rss = cn.Execute(sqll)
Do Until rs.EOF
nf = rs.fields(0)
Do Until Rss.EOF
gys = Rss.fields(0)
sqlll = "select TOP 5 * from [源数据$A2:E] WHERE 年份= " & nf & " AND 供应商='" & gys & "' ORDER BY 金额CNY DESC "
n = Range("i65536").End(xlUp).Row
Cells(n + 1, "h") = "年份": Cells(n + 1, "i") = nf
Cells(n + 2, "h") = "供应商": Cells(n + 2, "i") = gys
Range("h" & n + 3).CopyFromRecordset cn.Execute(sqlll)
Rss.movenext
Loop
rs.movenext
Loop
End Sub
|
|