vba 将列从一个 Excel 工作表复制到另一个 Excel 工作表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6382526/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:35:45  来源:igfitidea点击:

Copy column from one Excel sheet to another Excel sheet

excelvbaexcel-vba

提问by deepak goel

I want to copy particular columns from one Excel sheet to another Excel sheet in a different workbook. How can I use a macro to copy some columns to different Excel sheet?

我想将特定列从一个 Excel 工作表复制到另一个工作簿中的另一个 Excel 工作表。如何使用宏将某些列复制到不同的 Excel 工作表?

回答by Alex P

Suppose you have two workbooks (source and target) and you want to copy column A in the source workbook to column A in the target workbook.

假设您有两个工作簿(源和目标),并且您希望将源工作簿中的 A 列复制到目标工作簿中的 A 列。

Sub CopyColumnToWorkbook()
    Dim sourceColumn As Range, targetColumn As Range

    Set sourceColumn = Workbooks("Source").Worksheets("Sheet1").Columns("A")
    Set targetColumn = Workbooks("Target").Worksheets("Sheet1").Columns("A")

    sourceColumn.Copy Destination:=targetColumn
End Sub

Clearly you can change the columns as you see fit.

显然,您可以根据需要更改列。