|
- 'http://club.excelhome.net/thread-1195938-1-1.html
- Sub ADO加字典法_鞋()
- CRR = ActiveSheet.Range("A1:C61")
- Dim cnn As Object, rs As Object, SQL$, MyPath$, MyFile$, s$, t$
- Dim arr, brr(1 To 65530, 0 To 2), d As Object, i&, j&, m&
- Set d = CreateObject("scripting.dictionary")
- MyPath = ThisWorkbook.Path & ""
- MyFile = Dir(MyPath & "*.xls")
- Do While MyFile <> ""
- If InStr(MyFile, ThisWorkbook.Name) = 0 Then
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & MyPath & MyFile
- Set rs = cnn.OpenSchema(20)
- Do Until rs.EOF
- If rs.Fields("TABLE_TYPE") = "TABLE" Then
- s = Replace(rs("TABLE_NAME").Value, "'", "")
- If Right(s, 1) = "$" Then
- If InStr(s, "专卖") Then
- SQL = "select * from [" & s & "A2:U] where 专卖店名 is not null and 专卖店名<>'合计'"
- arr = cnn.Execute(SQL).GetRows
- For i = 0 To UBound(arr, 2)
- t = arr(0, i)
- If Not d.Exists(t) Then
- m = m + 1
- d(t) = m
- For j = 0 To 0
- brr(m, j) = arr(j, i)
- brr(m, 1) = "鞋"
- Next
- Else
- brr(d(t), 2) = brr(d(t), 2) + arr(12, i)
- End If
- Next
- End If
- End If
- End If
- rs.MoveNext
- Loop
- End If
- MyFile = Dir()
- Loop
- ActiveSheet.UsedRange.Offset(1, 2).ClearContents
- ReDim drr(1 To UBound(CRR), 1 To 1)
- For X = 2 To 44
- For Y = 1 To m
- If InStr(CRR(X, 1), brr(Y, 0)) Then
- K = K + 1
- drr(K, 1) = brr(Y, 2)
- End If
- Next Y
- Next X
- [C2].Resize(UBound(CRR), 1) = drr
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
|