简体   繁体   English

将数据复制/粘贴到数据的最后一行/列之后/之后。 从旧工作簿到新工作簿

[英]copy/ paste data to/after the last row/column of data. from old workbook to new workbook

I am updating a weekly Master file. 我正在更新每周主文件。 As a result, I am trying to copy and paste the data from the source file to the Master sheet. 如此一来,我试图将数据从源文件复制并粘贴到主表中。 Now, The data needs to be pasted to the columns and rows after the data of the previous week. 现在,需要将数据粘贴到上周数据之后的列和行中。 So for example if last weeks data ends ("H70:M70"), I need the new pasted data to go to ("H71:M71"). 因此,例如,如果上周数据结束(“ H70:M70”),我需要将新粘贴的数据转到(“ H71:M71”)。 Also, the new pasted data has many rows, so nexts week data has to be pasted after the last row/column of this weeks data ie ("H230:M230"). 另外,新粘贴的数据有很多行,因此下周的数据必须粘贴在该周数据的最后一行/列之后,即(“ H230:M230”)。 Please Help. 请帮忙。

Option Explicit
Sub Copydata()
Dim myWB As Workbook
Dim thisWB As Workbook
Dim thisWS As Worksheet

Application.ScreenUpdating = False    

Set myWB = Workbooks.Open("C:\Users\jjordan\Desktop\test.xlsx")

myWB.Sheets("Sheet1").Range("A8:F17").Copy

Set thisWB = ThisWorkbook
Set thisWS = thisWB.Sheets("Test data")

thisWB.Activate
thisWS.Range("H71:M71").PasteSpecial _
    Paste:=xlPasteValues, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

With Application
    .CutCopyMode = False
    .ScreenUpdating = True
End With

myWB.Close

End Sub 结束子

James, are you familiar with End() in VBA? James,您熟悉VBA中的End()吗?

lastRow = ActiveSheet.Cells(Rows.Count,1).End(xlUp).Row

This will go to the last possible Cell in column 1 of your worksheet, then go up until it finds a Cell containing data and return the corresponding row. 这将转到工作表第1列中最后一个可能的单元格,然后向上直到找到包含数据的单元格并返回相应的行。

The other possible arguments for End() are xlDown, xlToLeft, and xlToRight. End()的其他可能参数是xlDown,xlToLeft和xlToRight。 They can be used to find last/first columns and rows. 它们可用于查找最后/第一列和行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据从一个Excel工作簿复制到最后一行中的另一个工作簿 - Copy Data from one Excel Workbook to Another Workbook in Last row 将数据从一个工作簿复制到另一工作簿的最后一行 - Copy data from one workbook to another workbook last row 用于在工作簿中的多个工作表上复制和粘贴最后一列数据的 VBA 脚本 - VBA Script to copy and Paste last column of data on multiple sheets in a workbook VBA 不起作用(从一个文件复制数据并粘贴到最后一行数据下方的不同工作簿) - VBA not working (copy data from one file and paste to different workbook below last row of data) 从一个工作簿中复制特定数据并将其粘贴到另一工作簿中(从第二行粘贴) - Copy specific data from one workbook and paste it into another workbook (paste from second row) VBA-如何从其他工作簿复制所有数据并将其粘贴到最后一行 - VBA - How to copy all data from other workbook and paste it in last row 将数据从多个工作簿的最后一行复制并粘贴到另一个工作簿中的工作表 - Copy and paste data from multiple workbooks last row to a worksheet in another Workbook 仅将过滤后的数据复制并粘贴到新工作簿 - Copy and paste only filtered data to new workbook 输入所有必需数据后,将新数据从一个工作簿复制并粘贴到另一个工作簿 - Copy and paste new data from one workbook to another after all required data has been entered VBA如何从工作表中复制数据并将其粘贴到新工作簿 - VBA How to copy data from a sheet and paste to a new workbook
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM