VBA copy-paste offset to another workbook

断了今生、忘了曾经 提交于 2019-12-12 05:14:54

问题


I would need your advice if you could help me because my VBA knowledge is very poor. I have 4 columns and thousands of rows, I would like that first row to be copied-pasted transposed in another workbook by hitting a command button, after that the second hit of button to overwrite the previous copy-paste and so on (in the second workbook I have some formulas which are gonna apply to the new values and I have to check the results). Many thanks in advance!

Here is the code that I have done it to copy-paste from one workbook to the other one (the code is moving to the next row but it doesn't copy-paste the values on the other workbook, in the other workbook are the same first values, so here its my dilemma):

Private Sub CommandButton1_Click()

ActiveCell.Offset(1, 0).Activate

Workbooks("Book1.xlsm").Worksheets("Sheet2").Range("B4:E4").Copy
Workbooks("Book2.xlsm").Worksheets("Sheet1").Range("B20").PasteSpecial Transpose:=True

Application.CutCopyMode = False

End Sub

回答1:


Please try this

Private Sub CommandButton1_Click()
ActiveCell.Offset(1, 0).Activate
Workbooks("Book1.xlsm").Worksheets("Sheet2").Range("A" & ActiveCell.Row & ":E" & ActiveCell.Row).Copy
Workbooks("Book2.xlsm").Worksheets("Sheet1").Range("B20").PasteSpecial Transpose:=True
End sub


来源:https://stackoverflow.com/questions/43676014/vba-copy-paste-offset-to-another-workbook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!