如何将Sheet1的“ case”列插入Sheet2,然后在“ Sheet2”的第1页到第2页分页?

时间:2019-04-07 20:44:27

标签: excel vba

我的VBA脚本应按案例标题搜索范围行,然后复制所有数据行,粘贴到Sheet2->“ A122,B122,C122,D122”中,然后在分页符后将循环数据复制到第2、3页, 4.任何特别的评论,积极的反馈都将受到任何专家向导的赞赏。

Sub AddPageBreak ()

Dim LastRow As Long
Dim Sheet2 As Worksheet
Dim Unit As Integer
Dim i As Long
Dim r As Long


Set Results = Sheets("Sheet2")
LastRow = Results.Cells(Results.Rows.Count, "Z").End(xlUp).Row

Range("A18:A50").Copy
Results.Range("A" & LastRow + 1).PasteSpecial xlValues
Range("B18:B50").Copy
Results.Range("B" & LastRow + 1).PasteSpecial xlValues
Range("J18:J50").Copy
Results.Range("C" & LastRow + 1).PasteSpecial xlValues
Range("R18:R50").Copy
Results.Range("D" & LastRow + 1).PasteSpecial xlValues

Application.DataEntryMode = False




For i = 1 To Sheet1.Cells(Sheet1.Rows.Count, 1).End(xlUp).Row 
    Select Case CStr(Sheet1.Cells(i, 18).Value)
    Case "Numbers"
        Sheet2.Cells(122, 1).Value = Sheet1.Cells(i, 1).Value
    Case "No Active"
        Sheet2.Cells(122, 1).Value = Sheet1.Cells(i, 1).Value
    Case "Cleared"
        Sheet2.Cells(122, 1).Value = Sheet1.Cells(i, 1).Value
    Case "Notice"
        Sheet2.Cells(122, 1).Value = Sheet1.Cells(i, 1).Value
    Case "DM Letter "
        Sheet2.Cells(122, 1).Value = Sheet1.Cells(i, 1).Value
    Case "Letters "
        Sheet2.Cells(122, 1).Value = Sheet1.Cells(i, 1).Value
    Case "Estimate Payment"
        Sheet2.Cells(122, 1).Value = Sheet1.Cells(i, 1).Value


    End Select
Next i


Unit = Range("I1").Value
i = 2
r = 2

Do While i <= Unit

If Cells(r, 1).Value = "Unit" Then

  Rows(r).PageBreak = xlPageBreakAutomatic
  i = i + 1

End If

r = r + 1

Loop


End Sub

0 个答案:

没有答案