[英]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.