COPY WB1的最后一行并粘贴到最后一行WB2

时间:2014-02-10 14:41:50

标签: excel vba excel-vba

我有两个工作簿1. thisWB 2. newWB
现在我需要将数据从thisWB的lastblank行+ 1复制到newWB工作簿并粘贴到lastblank row + 1中。 我已经放了一些像下面这样的代码,但它不起作用,你能用以下代码建议问题是什么

Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Dim ws As Worksheet
Dim blankcell As Long
blankcell = Columns(1).Find("", LookIn:=xlValues, lookat:=xlWhole).Row
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Windows(thisWB).Sheets("BS All Entities").Rows(blankcell + 1 & ":" & LastRow).Copy Destination:=Windows(newWB).Sheets("BS All Entities").Cells(Rows.Count, "A").End(xlUp).Offset(2, 0)
Application.ScreenUpdating = True

提前感谢您的帮助。 KR 的Manoj

2 个答案:

答案 0 :(得分:1)

请尝试以下代码:

Application.ScreenUpdating = False
Dim rngLastColumnOld As Long
Dim rngLastRowOld As Long
Dim rngTemp As Range
Dim rngFirstBlankOld As Range
Dim rngCopyFrom As Range
Dim rngFirstBlankNew As Range


With Windows(thisWB).Sheets("BS All Entities")
    Set rngTemp = .Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)
            If rngTemp Is Nothing Then
                rngLastColumnOld = 1
            Else
                rngLastColumnOld = rngTemp.Column
            End If
    rngLastRowOld = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Set rngFirstBlankOld = .Range("A1").End(xlDown).Offset(1)
    Set rngCopyFrom = .Range(rngFirstBlankOld, .Cells(rngLastRowOld, rngLastColumnOld))
End With

Set rngFirstBlankNew = Windows(newWB).Sheets("BS All Entities").Cells(Rows.Count, "A").End(xlUp).Offset(1).EntireRow

rngFirstBlankNew.Resize(rngCopyFrom.Rows.Count, rngCopyFrom.Columns.Count).Value = rngCopyFrom.Value
Application.ScreenUpdating = True

答案 1 :(得分:0)

通过此链接

http://www.mrexcel.com/forum/excel-questions/755467-using-visual-basic-applications-paste-data-multiple-sheets.html

只有更改而不是相同的工作簿表我正在使用不同的工作簿表