|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 生成标签()
Application.ScreenUpdating = False
With Sheets("原始明细")
r = .Cells(Rows.Count, 2).End(xlUp).Row
If r < 4 Then MsgBox "原始明细为空!": End
ar = .Range(.Cells(3, 1), .Cells(r, 26))
mc = .[a1]
End With
If (r - 3) / 2 = Int((r - 3) / 2) Then
gs = (r - 3) / 2
Else
gs = Int((r - 3) / 2) + 1
End If
With Sheets("标签")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs >= 6 Then .Rows("6:" & rs).Delete
.Range("B2:B5,E2:E4,E5") = Empty
m = 6
For i = 2 To gs
.Rows("1:5").Copy .Cells(m, 1)
m = m + 5
Next i
m = 1
For i = 2 To UBound(ar) Step 2
If ar(i, 2) <> "" Then
x = 0
For j = 2 To 4
x = x + 1
.Cells(m + x, 2) = ar(i, j)
Next j
.Cells(m + 4, 2) = ar(i, 26)
End If
If i + 1 <= UBound(ar) Then
If ar(i + 1, 2) <> "" Then
x = 0
For j = 2 To 4
x = x + 1
.Cells(m + x, 5) = ar(i + 1, j)
Next j
.Cells(m + 4, 5) = ar(i + 1, 26)
End If
End If
m = m + 5
Next i
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|