|
楼主 |
发表于 2018-12-24 17:31
|
显示全部楼层
- 'http://club.excelhome.net/thread-1195938-1-1.html
- Sub 同夹多薄多表_AB列双条件分类_C列汇总_ADO加字典法()
- Dim 结果数组(1 To 65530, 0 To 2)
- Set 字典 = CreateObject("scripting.dictionary")
- 路径 = ThisWorkbook.Path & "": 外薄 = Dir(路径 & "*.xls")
- Do While 外薄 <> ""
- If InStr(外薄, ThisWorkbook.Name) = 0 Then
- Set 连接 = CreateObject("ADODB.Connection")
- 连接.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & 路径 & 外薄
- Set 记录 = 连接.OpenSchema(20)
- Do Until 记录.EOF
- If 记录.Fields("TABLE_TYPE") = "TABLE" Then
- 外表 = Replace(记录("TABLE_NAME").Value, "'", "")
- If Right(外表, 1) = "$" Then
- SQL = "select * from [" & 外表 & "] where 物品 is not null"
- 记录数组 = 连接.Execute(SQL).GetRows
- For 行 = 0 To UBound(记录数组, 2)
- 条件列 = 记录数组(0, 行) & 记录数组(1, 行)
- If Not 字典.Exists(条件列) Then
- 计数器 = 计数器 + 1
- 字典(条件列) = 计数器
- For 列 = 0 To 2
- 结果数组(计数器, 列) = 记录数组(列, 行)
- Next
- Else
- 结果数组(字典(条件列), 2) = 结果数组(字典(条件列), 2) + 记录数组(2, 行)
- End If
- Next
- End If
- End If
- 记录.MoveNext
- Loop
- End If
- 外薄 = Dir()
- Loop
- ActiveSheet.UsedRange.Offset(1).ClearContents
- [a2].Resize(计数器, 3) = 结果数组
- 记录.Close: Set 记录 = Nothing
- 连接.Close: Set 连接 = Nothing
- End Sub
复制代码 |
|