|
楼主 |
发表于 2019-3-29 23:04
|
显示全部楼层
Private Sub CommandButton2_Click()
Dim HS As Integer
HS = 6
Do While Cells(HS, "A").Value <> "" '判断表1中共有多上行
HS = HS + 1
Loop
Dim XH As Integer '设置A4-列印中的序列号
XH = 1
Dim H As Integer
For H = 6 To HS '定义循环次数
Cells(H, "A").Value = XH '给序列赋值
XH = XH + 1
Sheets("表1").Range(Cells(H, "J")).Select
' Range(Cells(H, "J")).Select
Selection.Copy
Sheets("A4-列印").Range(Cells(H, "B")).Select
' Range(Cells(H, "B")).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Sheets("表1").Range(Cells(H, "E"), Cells(H, "G")).Select
' Range(Cells(H, "E"), Cells(H, "G")).Select
Selection.Copy
Sheets("A4-列印").Range(Cells(H, "C")).Select
' Range(Cells(H, "C")).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Sheets("表1").Range(Cells(H, "K")).Select
' Range(Cells(H, "K")).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("A4-列印").Range(Cells(H, "F")).Select
' Range(Cells(H, "f")).Select
ActiveSheet.Paste
Next
Range(Cells(HS + 1, "A"), Cells(HS + 1, "E")).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.FormulaR1C1 = "汇总"
Range(Cells(HS + 1, "F")).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-9]C:R[-1]C)"
Range(Cells(5, "A"), Cells(HS + 1, "F")).Select
Range(Cells(HS + 1, "F")).Activate
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
|
|