我有一个代码工作但需要不同的功能。我正在将数据从源工作簿移动到目标工作簿。我需要插入数据,但需要在插入的数据下面留一个空行。目标表中的最后一行是Sum Total行,我需要保留而不是覆盖。这就是我现在所选择的30行范围。
Sub EndofDayTransfer_Workbook()
'Defines this active workbook as "Source".
Dim Sourcewb As Workbook
Set Sourcewb = ThisWorkbook
Application.ScreenUpdating = False
Dim LastRow As Long
'Lily's scores transfered
Worksheets("Lily").Activate 'Activates tab "Lily" for copy paste that follows.
Sheets("Lily").Select
LastRow = Range("B" & rows.Count).Row
Range("B3:AK30").Select
Selection.Copy
Workbooks.Open ("C:\Users\U558683\Desktop\QA VBA Project\Processor Scorecard_Lily.xlsx") 'Opens Lily's Scorecard.
Worksheets(Worksheets.Count).Select 'Selects Last worksheet page
'Range("B3").Select 'Selects destination
'Inserts Copied data
Dim ws As Worksheet
Set ws = ActiveSheet
For Each cell In ws.Columns(2).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
ActiveSheet.Range("B2").rows("1:1").Insert Shift:=xlDown
ActiveSheet.Paste 'Pastes Selection !!!!!!!!!
Application.CutCopyMode = False 'Clears clip board for next copy action.
ActiveWorkbook.Close (True) 'Closes Lily's Scorecard
Sourcewb.Activate 'Reactivates Analyst workbook.
Stop 'Stops action
End Sub
另外,我有这个代码将数据复制到第一个空白并粘贴在同一工作簿中的工作表中的下一个空白处。我无法将此代码合并到上面的代码中,因为它具有我想要实现的功能。
Sub CopyRows()
Dim LastRow As Long
Application.ScreenUpdating = False
'Select source location and range
Sheets("Data1").Select
Set destRng = Sheets("Data2").Cells(Rows.Count, "A").END(xlUp).Offset(1, 0)
'Copy selected range to last row
LastRow = Range("A" & Rows.Count).END(xlUp).Row
Range("A1:D" & LastRow).Copy Destination:=destRng
'Select destination and range and paste
With Sheets("Data2")
Columns("A:D").AutoFit
End With
End Sub