|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
填入对应列 何为填入?我的理解就是据已知的填入,下面的参考
- Sub test2() ' 事先要说明
- Dim Conn As Object, rs As Object
- Dim strConn As String, SQL As String, i As Integer
-
- Set Conn = CreateObject("ADODB.Connection")
- If Application.Version < 12 Then
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
- End If
- Conn.Open strConn & ThisWorkbook.FullName
-
- SQL = "SELECT a.*,b.* FROM [sheet3$A1:F] a LEFT JOIN [sheet1$A1:D] b ON a.车间=b.所属车间 WHERE LEN(本次计划数量)"
- SQL = "SELECT 编码,图号,名称,'' AS 材料系列,'' AS 材料大类,'' AS 日期,'' AS 备注,SUM(数量*本次计划数量) AS 需求数量,'' AS 需求日期,'' AS 计划编号,'' AS 计划描述,'' AS 年度净需求量,SUM(数量*年度计划数量) AS 年度生产数量,'' AS 周度净需求量,SUM(数量*周度计划数量) AS 周度生产数量 FROM (" & SQL & ") GROUP BY 编码,图号,名称"
- Set rs = Conn.Execute(SQL)
-
- With Worksheets("sheet2").Range("A2")
- .CurrentRegion.ClearContents
- For i = 0 To rs.Fields.Count - 1
- .Offset(0, i) = rs.Fields(i).Name
- Next
- .Offset(1).CopyFromRecordset rs
- End With
-
- Set rs = Nothing
- Conn.Close
- Set Conn = Nothing
- Beep
- End Sub
复制代码
|
|