2014-02-10 39 views
0

貼我有兩個工作簿1. thisWB 2. newWB
現在我需要把數據從thisWB的lastblank排+ 1 newWB工作簿中複製和lastblank排+ 1粘貼。
我已經把一些代碼象下面,但它不工作,你可以建議的是與下面的代碼COPY最後一行從WB1和最後一行WB2

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 馬諾

+0

'lastblank row + 1'?你的意思是來自上次使用的行的數據? – 2014-02-10 14:51:23

回答

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 
+0

喜 對不起,我不是很清楚,這裏是我想 我有兩個工作簿 1. Father.xlsx 2. Mother.xlsx 一些100行後 在一個工作簿(Father.xlsx)有一個空白行並在其下面再次顯示一些數據。我想將這些行復制到已存在一些數據的工作簿二(Mother.xlsx),我想在留下一行空白後將這些複製的行粘貼到工作簿二。 簡而言之,一個程序可以識別工作簿上的最後一行,然後複製下面的所有數據,然後進入工作簿二找到最後的結尾行,然後將一行留空並粘貼數據。 – user3293280

+0

你想在找到空白行之前複製一些100行?或者是空白行下的所有東西?如果你想要在空白行下面的所有東西,那麼將所有的數據都放在工作表底部? – user2140261

+0

所有事情一旦遇到空白行,我的意思是任何事情,甚至空白 – user3293280