vba 如何使用宏将 Excel 2007 中的数据从一张工作表复制到另一张工作表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2454106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I copy data from one sheet to another sheet in Excel 2007 using a macro?
提问by Mwaseem Alvi
I am using MS Office 2007. How can I copy whole data from sheet one to sheet two? I want to copy the whole data from row 5 to onward in sheet two. The whole scenario is given below in detail.
我正在使用 MS Office 2007。如何将整个数据从工作表一复制到工作表二?我想将整个数据从第 5 行复制到第二页。下面详细给出整个场景。
Sheet one:
Copy the data from column B and Row 3
表一:
复制 B 列和第 3 行的数据
Sheet Two:
Paste the Copied Data in Column B and Row 3
第二表:
将复制的数据粘贴到 B 列和第 3 行
Sheet One:
Copy the whole data from Column B to Column G and Row 5 to onward
表一:
将整个数据从 B 列复制到 G 列和第 5 行向前
Sheet Two:
Paste whole copied data in sheet two from last filled row to onward
第二表:将
整个复制的数据从最后填充的行粘贴到第二表中
Data doesn't overwrite on any row or column. Every data will be added in sheet two from sheet one when macro will be run.
数据不会覆盖任何行或列。运行宏时,每个数据都将添加到工作表一的工作表二中。
回答by Stewbob
The best way to learn how to do this is to record a macro. Excel has a very good macro recorder. Just start to record a new macro, then manually perform all the steps you describe in your question. After you have finished, stop the macro recorder and take a look at the code that Excel generated for you.
学习如何做到这一点的最好方法是录制一个宏。Excel 有一个非常好的宏记录器。只需开始录制新宏,然后手动执行您在问题中描述的所有步骤。完成后,停止宏记录器并查看 Excel 为您生成的代码。
Alt+F11 is the shortcut key to get to the VBA code editor in Excel.
Alt+F11 是进入 Excel 中 VBA 代码编辑器的快捷键。
回答by guitarthrower
This should do the trick. But before you try, do a SaveAs to a different file, so if it doesn't give the desired results you can go back to the other version. There are no Undos with macros.
这应该可以解决问题。但是在您尝试之前,请对不同的文件执行另存为,因此如果它没有给出所需的结果,您可以返回到另一个版本。没有带有宏的撤消。
Sub CopyInfo()
Sheet2.Range("B3").Value = Sheet1.Range("B3").Value
Sheet1.Range("B5:G65000").Copy
Sheet2.Range("B5").Paste
Application.CutCopyMode = False
End Sub