|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub a()
Dim cnn As Object, rs As Object, SQL$, Mypath$, MyName$, arr
Dim i%, j As Byte, d, x%, y%, m%
Set d = CreateObject("Scripting.Dictionary")
Application.ScreenUpdating = False
Mypath = ThisWorkbook.Path & "\"
MyName = Dir(Mypath & "*.xls")
Do While MyName <> ""
If MyName <> ThisWorkbook.Name Then
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=NO';Data Source=" & Mypath & MyName
For j = 1 To 3
SQL = "select F1,F2,""" & Replace(MyName, "基数.xls", "") & Format(j, "00") & """ from [" & Replace(MyName, "基数.xls", "") & Format(j, "00") & "$f4:g] where F1 IS NOT NULL"
Set rs = cnn.Execute(SQL)
arr = rs.getRows
For m = 0 To UBound(arr, 2)
d(arr(0, m) & arr(2, m)) = arr(1, m)
Next
Next
End If
MyName = Dir()
Loop
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
For j = 1 To Sheets.Count
arr = Sheets(j).Range("f3:r" & Sheets(j).Range("f9999").End(3).Row)
For x = 2 To UBound(arr)
For y = 2 To UBound(arr, 2)
arr(x, y) = d(arr(x, 1) & arr(1, y))
Next
Next
Sheets(j).[f3].Resize(UBound(arr), UBound(arr, 2)) = arr
Next
Set d = Nothing
Application.ScreenUpdating = True
End Sub
|
|