Sub 转置()
Dim ar As Variant
Dim br()
With Sheet1
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 7 Then MsgBox "请先查询数据!": End
ar = .Range("a7:f" & r)
End With
ReDim br(1 To 4, 1 To UBound(ar) + 1)
rr = Array([b5], [b6], "", "", "正品数量", "次品数量")
For j = 1 To UBound(ar, 2)
If j <> 3 And j <> 4 Then
n = n + 1
br(n, 1) = rr(j - 1)
For i = 1 To UBound(ar)
br(n, i + 1) = ar(i, j)
Next i
End If
Next j
With Sheets("sheet4")
rs = .Cells(Rows.Count, 2).End(xlUp).Row + 1
.Cells(rs, 2).Resize(n, UBound(br, 2)) = br
End With
MsgBox "ok!"
End Sub
|