|
尐_Oo_超.超 发表于 2014-6-30 12:12
如果把两个工作簿的表格拓展一下,代码该如何编写呢?
请查看附件: - Sub Macro1()
- Dim cnn As Object, i&, s$, t$, SQL$, d As Object, sh As Worksheet
- Set d = CreateObject("scripting.dictionary")
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider = Microsoft.Ace.Oledb.12.0;Extended Properties ='Excel 12.0;hdr=no';Data Source =" & ThisWorkbook.Path & "" & Split(ThisWorkbook.Name, "月")(0) & "月评分表.xlsx"
- arr = cnn.Execute("select * from [评分表$a4:j] where f2 is not null").GetRows
- For i = 0 To UBound(arr, 2)
- If Not IsNull(arr(0, i)) Then t = arr(0, i)
- d(t & vbTab & arr(1, i) & vbTab & "一") = arr(5, i)
- d(t & vbTab & arr(1, i) & vbTab & "二") = arr(9, i)
- Next
- For Each sh In Sheets
- s = sh.Name
- arr = sh.[a1].CurrentRegion
- ReDim brr(3 To UBound(arr), 1 To 1)
- For i = 3 To UBound(arr)
- If Len(arr(i, 1)) Then t = arr(i, 1)
- brr(i, 1) = d(s & vbTab & arr(i, 2) & vbTab & t)
- Next
- sh.[f3].Resize(i - 3) = brr
- Next
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
|