在另一个工作簿中添加一行来复制单元格

所以我必须从一个工作簿复制单元格A1,B2和C3,并在列A,B,C中使用这些值在另一个工作簿(在最后一行)中添加一行。

这是我到目前为止,我认为我很接近,但我无法完成。 我不知道这个语法“Set lastrow = wNew.Cells。(Rows.Count,”A“)。End(xlUp).Row + 1”这是什么问题,

Sub Botão1_Clique() Dim wks As Worksheet Dim wNew As Worksheet Dim y As Workbook Dim lastrow As Long Application.ScreenUpdating = False Set wks = ActiveSheet Set y = Workbooks.Open("Y:\teste.xlsx") Set wNew = y.Sheets("GERAL") Set lastrow = wNew.Cells.(Rows.Count, "A").End(xlUp).Row + 1 wks.Cells(1, 1).Copy wNew.Cells(lastrow, 1).PasteSpecial Paste:=xlPasteValues wks.Cells(2, 2).Copy wNew.Cells(lastrow, 2).PasteSpecial Paste:=xlPasteValues wks.Cells(3, 3).Copy wNew.Cells(lastrow, 3).PasteSpecial Paste:=xlPasteValues Application.ScreenUpdating = True End Sub 

我也想closuresY:\ teste.xlsx工作簿,并显示一条消息“ROW ADDED”

您可以很好地参考WorkbooksWorksheets但也要确保您完全符合“ CellsRows 。 它们是工作表对象的属性,即ThisWorkbook.Worksheets("..").Rows

 Sub Botão1_Clique() Dim wks As Worksheet, wNew As Worksheet Dim y As Workbook Dim lastrow As Long Application.ScreenUpdating = False Set wks = ActiveSheet Set y = Workbooks.Open("Y:\teste.xlsx") Set wNew = y.Sheets("GERAL") With wNew lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 .Cells(lastrow, 1).Value = wks.Cells(1, 1) .Cells(lastrow, 2).Value = wks.Cells(2, 2) .Cells(lastrow, 3).Value = wks.Cells(3, 3) End With 'extra code as requested y.Close True 'save changes if TRUE MsgBox "ROW ADDED" Application.ScreenUpdating = True End Sub