|
求助说明:Sheet1 为数据源
Sheet2 为结果数据
Sub tt()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim arr, arrb
Dim i As Integer
Dim r As Integer
arr = Array("S", "M", "L", "XL", "XXL", "均码", "订做")
arrb = Array("日期", "款号加颜色", "颜色", "成本价", "单价", "件数", "码数")
cn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;imex=1';data source=" & ThisWorkbook.FullName
rs.Open "SELECT * FROM [sheet1$A:N]", cn, 3, 3
Sheet2.Range("A1:G65536").ClearContents
For i = 0 To 6
r = Sheet2.Range("A65536").End(xlUp).Row
sql = "SELECT 日期,款号加颜色,颜色,成本价,单价," & arr(i) & " FROM [sheet1$A:N]"
Sheet2.Range("A" & r + 1).CopyFromRecordset cn.Execute(sql)
Sheet2.Range("G" & r + 1, "G" & r + rs.RecordCount - 1) = arr(i)
Sheet2.Range("A1:G1") = arrb
Next
rs.Close
cn.Close
Set cn = Nothing
Set rs = Nothing
Sheet2.Activate
Range("A1").Activate
End Sub
问题:当宏运行完后,为什么会产生一个空行数据(红色单元格处)
并且,结果数据已错位!!!
敬盼
改正解答
谢谢!!!!
[ 本帖最后由 lym321 于 2010-6-2 23:44 编辑 ] |
|