1

感谢您在这里所做的所有努力,我已经逆向工程并开发了一个代码,但我在一件小事上遇到了困难。从 WS2 复制时我想要做的是粘贴,因为我不想导出AD:AR导致工作簿崩溃的列中包含的所有公式。

Sub Copyandpaste()
    Dim LastRow As Long
    Dim ws1 As Worksheet, ws2 As Worksheet

    Set ws1 = ActiveWorkbook.Sheets("RAW DATA")
    Set ws2 = ActiveWorkbook.Sheets("DATA INPUT")

    LastRow = ws1.UsedRange.Rows.Count

    With ws2
        .Range("A2:AR2" & .Cells(Rows.Count, "G").End(xlUp).Row).Copy Destination:=ws1.Range("A" & LastRow + 1)
        For Each WS In ThisWorkbook.Worksheets
            For Each PT In WS.PivotTables
                PT.RefreshTable
            Next PT
        Next WS
    End With
End Sub
4

1 回答 1

0

这是你正在尝试的吗?

Sub Copyandpaste()
    Dim ws1LRow As Long, ws2LRow As Long
    Dim ws1 As Worksheet, ws2 As Worksheet

    Set ws1 = ThisWorkbook.Sheets("RAW DATA")
    Set ws2 = ThisWorkbook.Sheets("DATA INPUT")

    With ws1
        ws1LRow = .Cells.Find(What:="*", _
                    After:=.Range("A1"), _
                    Lookat:=xlPart, _
                    LookIn:=xlFormulas, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious, _
                    MatchCase:=False).Row + 1
    End With

    With ws2
        ws2LRow = .Range("G" & .Rows.Count).End(xlUp).Row

        .Range("A2:AR" & ws2LRow).Copy

        ws1.Range("A" & ws1LRow).PasteSpecial xlPasteValues

'        For Each WS In ThisWorkbook.Worksheets
'            For Each PT In WS.PivotTables
'                PT.RefreshTable
'            Next PT
'        Next WS
    End With
End Sub
于 2013-04-04T10:38:35.800 回答