简体   繁体   English

Excel宏数据从一个工作簿传输到另一个

[英]Excel Macro Data Transfer from One Workbook to Another

Hello I created a program that automatically scrapes data from a website and paste/formats it into an excel sheet. 您好,我创建了一个程序,该程序会自动从网站上抓取数据并将其粘贴/格式化为Excel工作表。 However I would like that data to then be transferred into another excel Workbook (One that already exists). 但是,我希望将这些数据传输到另一个excel工作簿(一个已经存在的工作簿)中。 The macro below transfers the data into another excel workbook but it keeps pasting the transferred data over the data that's been already been previously transferred. 下面的宏将数据传输到另一个excel工作簿中,但仍将已传输的数据粘贴到先前已传输的数据上。 How can I get it to transfer and paste the new data starting with the next blank row under the already previously transferred data. 我如何获取它来传输和粘贴新数据,并从先前已传输的数据下的下一个空白行开始。 I saw in a previous post that: 我在上一篇文章中看到:

LastRow = Target.Range("A10000").End(xlUp).Row + 1, LastRow = Target.Range(“ A10000”)。End(xlUp).Row + 1

Can do this but I'm not sure how to implement this line in the macro generated vba that I already have. 可以这样做,但是我不确定如何在宏生成的vba中实现这一行。 Is there a way to do this without having to write another vba module to implement this? 有没有一种方法,而无需编写另一个vba模块来实现此目的? All help is appreciated! 感谢所有帮助!

Sub Transfer() 子转移()

Range("A2:G34").Select
Selection.Copy
Workbooks.Open Filename:= _
    "Book1.xlsx"
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Save
Range("C6").Select

End Sub 结束子

So I figured it out, and I didn't use a macro recording because I couldn't get that to 100% work for my project but after research and trial and error the code below worked exactly how I wanted it too. 所以我弄清楚了,我没有使用宏记录,因为我无法将其100%用于我的项目,但是经过研究和反复试验,下面的代码也完全按照我的要求工作了。 This works for transferring two different excel workbooks or just sheets! 这适用于传输两个不同的excel工作簿或仅工作表! I hope this helps someone. 我希望这可以帮助别人。

Sub Transfer()

Worksheets("Source data Sheet Name").Range("A2:G100").Copy
Workbooks.Open Filename:= _
"File Destination for target"

LastRow = Sheets("Target Sheet Name").Cells(Rows.Count, "A").End(xlUp).Row
ActiveSheet.Paste Destination:=Worksheets("Target Sheet Name").Range("A" & LastRow)

ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM