VBA复制粘贴到另一个工作簿的偏移量 [英] VBA copy-paste offset to another workbook

查看:167
本文介绍了VBA复制粘贴到另一个工作簿的偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您可以帮助我,我会需要您的建议,因为我的VBA知识非常差.我有4列和数千行,我希望通过单击命令按钮将第一行复制粘贴到另一工作簿中,然后第二次单击按钮以覆盖先前的复制粘贴,依此类推(在第二本工作簿中,我有一些适用于新值的公式,我必须检查结果).提前非常感谢!

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

推荐答案

请尝试以下操作

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

这篇关于VBA复制粘贴到另一个工作簿的偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆