|
Option Explicit
Sub a()
Dim cnn As Object, SQL$, s$, p$, f$
Set cnn = CreateObject("ADODB.Connection")
p = ThisWorkbook.Path & "\"
f = Dir(p & "*.CSV")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='text;FMT=Delimited(,);hdr=YES';Data Source=" & p
Do While f <> ""
SQL = SQL & " SELECT INT(交易日期) AS T,还款本金,还款利息,还款总金额,交易手续费 FROM " & f & " UNION ALL "
f = Dir()
Loop
SQL = Left(SQL, Len(SQL) - 11)
SQL = "SELECT T,SUM(还款本金),SUM(还款利息),SUM(还款总金额),SUM(交易手续费) FROM (" & SQL & ") GROUP BY T"
[A2:E999] = ""
[a2].CopyFromRecordset cnn.Execute(SQL)
cnn.Close
Set cnn = Nothing
Dim R%
R = [A999].End(3).Row
[a1].Offset(R, 0) = "合计"
[b1].Offset(R, 0).Resize(1, 4) = "=sum(b2:b" & R & ")"
End Sub |
评分
-
2
查看全部评分
-
|