|
典型的数据库内连接。
模拟结果有误,见“备份”中的黄色区域。
- Sub grf()
- Application.DisplayAlerts = False
- On Error Resume Next
- Set cnn = CreateObject("adodb.connection")
- Set rst = CreateObject("adodb.recordset")
- cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.FullName
- Sql = "select distinct 采购担当 from [零部件List$f:f] where 采购担当 is not null" '去重后的采购担当
- rst.Open Sql, cnn, 1, 3
- arr = rst.GetRows(-1, 0)
- For k = 0 To UBound(arr, 2)
- dd = arr(0, k) '采购担当
- Sql = "select a.*,变更后纳期,变更后数量 from [零部件List$a:g] a,[纳期要求$a:h] b where 采购担当=" & dd & " and a.产品=b.产品"
- Sheets(CStr(dd)).Delete '删除同名表后新增空表
- Sheets.Add after:=Sheets(Sheets.Count)
- With ActiveSheet
- .Name = dd
- .[a1].Resize(1, 9) = Array("产品", "零部件", "使用數", "供应商代码", "供应商", "采购担当", "B_LT", "要求纳期", "要求数量")
- .[a2].CopyFromRecordset cnn.Execute(Sql)
- .Columns.AutoFit
- End With
- Next
- Application.DisplayAlerts = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|