gpt4 book ai didi

Excel VBA : copy lots of columns

转载 作者:行者123 更新时间:2023-12-04 21:37:55 26 4
gpt4 key购买 nike

我想将所有数据从工作表复制到另一个新 Excel 文件的另一工作表。我试过这个:

Set wkb = Workbooks.Add
wkb.SaveAs myNewFile
ThisWorkbook.Worksheets("Sheet 2").Activate
Set Ticker = ThisWorkbook.Worksheets("Sheet 2").Range("A1").CurrentRegion
Ticker.Copy
wkb.Worksheets(1).Activate
Cells(1, 1).PasteSpecial xlPasteAll
wkb.Save
wkb.Close

我发现的问题是当有大量列时(例如,从 A 到 OV)它不会工作。你知道其他方法吗?

最佳答案

您可以完全跳过剪贴板:

Set wkb = Workbooks.Add
copyAddress$ = ThisWorkbook.Worksheets("Sheet 2").Range("A1").CurrentRegion.Address

With wkb
.SaveAs myNewFile
.Sheets(1).Range(copyAddress).Value = ThisWorkbook.Worksheets("Sheet 2").Range(copyAddress).Value
.Save
.Close True '// Assuming you would want to save changes
End With

或者您可以只复制整个工作表:
Set wkb = Workbooks.Add
ThisWorkbook.Sheets("Sheet 2").Copy Before:=wkb.Sheets(1)

关于Excel VBA : copy lots of columns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29741581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com