|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub CC()
Set cn = CreateObject("adodb.connection")
cn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
Sql = "SELECT distinct 部署名称,生产线名,工程名称,设备名称,设备编号 from [故障总表$]"
Set rs = cn.Execute(Sql)
Do Until rs.EOF
sqll = "select 故障编号,发生日,故障编号*0,设备停止类型,故障编号*0,故障编号*0 from [故障总表$] where 设备编号=" & rs.fields(4) & ""
n = [a65536].End(3).Row
a = rs.fields(0)
Cells(n - 1, 3) = rs.fields(0): Cells(n - 1, 7) = rs.fields(1): Cells(n - 1, 14) = rs.fields(2): Cells(n - 1, 18) = rs.fields(3): Cells(n - 1, 22) = rs.fields(4)
Range("a" & n + 1).CopyFromRecordset cn.Execute(sqll)
m = [a65536].End(3).Row
Range("a" & n).Offset(-1).Resize(2, 23).Copy Cells(m + 3, 1)
rs.movenext
Loop
End Sub |
|