|
- Sub ChaiFen()
- Dim i%, cnn As Object
- Dim arr
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- On Error Resume Next
- MaxRow = ActiveSheet.UsedRange.Find("*", , , , , xlPrevious).Row
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=YES;';Data Source=" & ThisWorkbook.FullName
- Sql = "select distinct 使用单位 from [201504$a4:k" & MaxRow & "]"
- arr = cnn.Execute(Sql).getrows
- Set f = Workbooks.Open(ThisWorkbook.Path & "\部门表.xls")
- For Each UseUnit In arr
- Sql = "select 序号,器具名称,规格型号,生产厂家,出厂编号,有效日期,检定周期,检定人,安装位置 from [201504$a4:k" & MaxRow & "] where 使用单位='" & UseUnit & "'"
- With f
- For Each sh In Worksheets
- With sh
- If sh.Name = UseUnit Then
- UnitMaxRow = .UsedRange.Find("*", , , , , xlPrevious).Row
- .Range("a3:i" & UnitMaxRow).ClearContents
- .Range("a3").CopyFromRecordset cnn.Execute(Sql)
- GoTo aa
- End If
- End With
- Next
- End With
- aa:
- Next
- cnn.Close
- f.Close True
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 说明和数据都很乱,不知道是不是你想要的。 |
|