Office中国论坛/Access中国论坛
标题:
关于三个条数据引用(求救)
[打印本页]
作者:
gaowehu
时间:
2015-4-4 08:13
标题:
关于三个条数据引用(求救)
将出库表中满足料号,批号,部门三个条件的出库数量引用到总表内各个部门下面,请大虾们看有木有好的办法
作者:
fxl447098457
时间:
2015-4-5 15:47
Sub MyQuery()
Dim cnn As Object
Set cnn = CreateObject("ADODB.Connection")
Dim rs As Object
Set rs = CreateObject("ADODB.Recordset")
Dim sql As String
Dim mybook As String
mybook = ThisWorkbook.FullName
With cnn
If Application.Version = "11.0" Then
.Provider = "microsoft.jet.oledb.4.0"
.ConnectionString = "extended properties=""excel 8.0;HDR=YES;"";data source=" & mybook
Else
.Provider = "microsoft.ACE.oledb.12.0"
.ConnectionString = "extended properties=""excel 12.0;HDR=YES;"";data source=" & mybook
End If
.Open
End With
sql = "transform sum(数量) select 料号,批号 from [" & ThisWorkbook.Path & "" & "出库表.xls].[Sheet1$] group by 料号,批号 pivot 部门"
rs.Open sql, cnn, 1, 3
With Worksheets("Sheet1")
.Cells.ClearContents
For j = 0 To rs.Fields.Count - 1
.Cells(1, j + 1) = rs.Fields(j).Name
Next
.Range("a2").CopyFromRecordset rs
End With
End Sub
复制代码
作者:
roych
时间:
2015-4-7 10:04
fxl447098457 发表于 2015-4-5 15:47
加个辅助列写公式就好了(不加辅助列也可以,但数组公式运行起来往往会慢一些)。
[attach]56085[/attach]
其实我不是特别赞成写代码的。
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3