|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
数据排版.rar
(18.26 KB, 下载次数: 2)
Option Explicit
Sub A()
Dim cnn, rs As Object, Sql As String, Arr, BRR, I%, J%, R%, t%, M%
Set cnn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.Recordset")
cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
Sql = "select distinct 型号 from [sheet2$A1:A] where len(型号)>0"
Arr = cnn.Execute(Sql).getrows
Sheets("数据").Cells.Clear
For I = 0 To UBound(Arr, 2)
Sql = "select distinct 色号 FROM [Sheet2$a1:c] where 型号='" & Arr(0, I) & "'"
BRR = cnn.Execute(Sql).getrows
t = t + 1
Sheets("模板").[a1:l27].Copy Sheets("数据").Range("a1").Offset((t - 1) * 28, 0)
Sheets("数据").[A1].Offset((t - 1) * 28, 0) = Arr(0, I)
M = 0
For J = 0 To UBound(BRR, 2)
Sql = "SELECT 卷号,数量 FROM [Sheet2$a1:d] where 型号='" & Arr(0, I) & "' AND 色号='" & BRR(0, J) & "'" _
& " order by val(卷号)"
If rs.State Then rs.Close
rs.Open Sql, cnn, 1, 1
With Sheets("数据")
Do While Not rs.EOF
M = M + 1
.Range("a3").Offset((t - 1) * 28 - 1, (M - 1) * 2) = BRR(0, J) & "#"
.Range("a4").Offset((t - 1) * 28, (M - 1) * 2).CopyFromRecordset rs, 20
Loop
End With
Next
Next
Set rs = Nothing
Set cnn = Nothing
End Sub
|
|