|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 打印()
- kname = Right([A3], Len([A3]) - 5)
- sday = [F3]
- Set conn = CreateObject("adodb.connection")
- Set rs = CreateObject("adodb.recordset")
- conn.Open "provider=microsoft.jet.oledb.4.0;" & _
- "extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
- Sql = "select 产品名称,单位,数量,单价,金额 from [明细$F1:M18] where 单位名称='" & kname & "' and 日期=#" & sday & "#"
- Set rs = conn.Execute(Sql)
- arr = rs.getrows
- For i = 0 To UBound(arr, 2)
- If i < 7 Then
- Cells(i + 5, 1) = arr(0, i)
- Cells(i + 5, 4) = arr(1, i)
- Cells(i + 5, 5) = arr(2, i)
- Cells(i + 5, 6) = arr(3, i)
- Cells(i + 5, 7) = arr(4, i)
- Else
- Sheets("打印").Copy after:=ActiveSheet
- Range("A5:G11").ClearContents
- For j = 7 To UBound(arr, 2)
- Cells(j - 2, 1) = arr(0, j)
- Cells(j - 2, 4) = arr(1, j)
- Cells(j - 2, 5) = arr(2, j)
- Cells(j - 2, 6) = arr(3, j)
- Cells(j - 2, 7) = arr(4, j)
- Next
- Exit For
- End If
- Next
- conn.Close
- Set conn = Nothing
- End Sub
复制代码 |
|