|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 hehex 于 2013-6-26 11:35 编辑
wang94103 发表于 2013-6-26 10:28
经过使用,可以使用,但有一个小问题,就是录入后会把分表“AAA","BBB","CCC"l里的计算库存的公式也弄没了 ...
当时就没太注意后面有使用公式,很简单,在复制数据之后将上面的公式也拉下来。使用filldown 方法就好了。
已经修改程序达成效果:- Sub ¼Èë()
- Application.ScreenUpdating = False
- Dim conn As Object, xrow As Long, brow As Long, i As Long, sqlstr$, sAdress$, sht As Worksheet
- Set conn = CreateObject("adodb.connection")
- conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
- sAdress = Range("a3", Cells(Rows.Count, "i").End(xlUp)).Address(0, 0)
-
- For Each sht In Worksheets
- If sht.Name <> "¼Èë" Then
- sqlstr = Select 日期,摘要,收入数量,发出数量,库存,备注,批号,小号 from [录入$" & sAdress & "] where 产品 = '" & sht.Name & "'"
- With sht
- xrow = .[a65535].End(xlUp).Row + 1
- .Range("a" & xrow).CopyFromRecordset conn.Execute(sqlstr)
- brow = .[a65535].End(xlUp).Row
- Range(.Cells(4, "e"), .Cells(brow, "e")).FillDown
- End With
- End If
- Next
- Sheets("录入").Activate
- Range(Range("a4"), Cells(Rows.Count, "i")).ClearContents
- Set conn = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|