|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 魂断蓝桥 于 2018-7-13 10:48 编辑
Option Explicit
Dim arr(1 To 50, 1 To 2), i As Integer
Sub Test()
Dim cnn, sql$, j%, n%, wjm$, BRR, CRR
Set cnn = CreateObject("ADODB.CONNECTION")
i = 0
Sea ThisWorkbook.Path & "\"
For j = 1 To i
If arr(i, 2) <> ThisWorkbook.Name Then
n = n + 1
If n = 1 Then
cnn.Open "Provider=Microsoft.Jet.OleDb.4.0;Extended Properties='Excel 8.0;HDR=NO';Data Source=" & arr(i, 1)
sql = "SELECT F1,F3 FROM [汇总$a5:c65] "
Else
sql = sql & " UNION ALL SELECT F1,F3 FROM [Excel 8.0;Database=" & arr(i, 1) & "].[汇总$a5:c65] "
End If
End If
Next
sql = "SELECT F1,SUM(F3) FROM (" & sql & ") GROUP BY F1"
BRR = cnn.Execute(sql).GETROWS
Set cnn = Nothing
CRR = [A5:A65]
For i = 1 To UBound(CRR)
For j = 0 To UBound(BRR, 2)
If CRR(i, 1) = BRR(0, j) Then
If CRR(i, 1) = "4" Then
CRR(i, 1) = BRR(1, j) / n
Else
CRR(i, 1) = BRR(1, j)
End If
Exit For
End If
Next
Next
[E5].Resize(UBound(CRR), 1) = CRR
End Sub
Sub Sea(P)
Dim f As Object
For Each f In CreateObject("scripting.FileSystemObject").GetFolder(P).Files
If f.Name Like "*.xls*" And f.Name <> ThisWorkbook.Name And Left(f.Name, 1) <> "~" Then
i = i + 1
arr(i, 1) = f.Path '& f.Name
arr(i, 2) = f.Name '& f.Name
End If
Next
For Each f In CreateObject("scripting.FileSystemObject").GetFolder(P).SubFolders
Sea f
Next
End Sub
|
评分
-
1
查看全部评分
-
|