【发布时间】:2019-03-04 23:29:42
【问题描述】:
一直在使用录制的宏完成工作簿之间的复制和粘贴的项目。录制的宏一直在工作,但是在阅读论坛时,人们说复制/粘贴方法需要更多时间才能运行宏,而且效率非常低。所以我试图找出一个复制目标 vba 行,它将复制从 Range(A2:G2000) 开始的几列,然后粘贴到从 (B6:H2000) 开始的范围区域。我不擅长这一点,并试图学习更多的效率。这里想到两件事。我有一个简单的复制和粘贴方法。但是会使用直接源 = 目的地。这可以做到吗?阅读本文后,您可能会看到另一个问题。为什么选择并复制/粘贴到第 2000 行?你的想法是正确的。一些报告(txt 文件)有 100 行,大约 300 行,不超过 1000 行,但我过度选择了副本,因为我不确定未来的 txt 文件。我在想如果你可以只选择最后一行使用的列会很酷。这远远超出了我。我很高兴有一种有效复制/粘贴的新方法。
我将不胜感激任何人可以提供的任何帮助。让我知道你的想法。
谢谢
婴儿潮
enter code here
Sub import_data()
'
'
'import_data
'
Application.ScreenUpdating = False
'
'Opens the txt file in excel - text delimited and leaves file open until
we close at bottom of code. There is no 'name for this workbook.
Workbooks.OpenText (Module33.FileDir + "\cf_data.txt"), Origin:=437, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1),
_
Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1)),
TrailingMinusNumbers:=True
'The line below is where I'm selecting data from the current opened
workbook and copying to another workbook
ActiveWindow.Sheet1.Range("A2:G2000").Copy
Destination:=Workbooks("Auto_Data.xlsm").Sheet2.Range ("B6:H2000")
'This info below is a (recorded marco). All works if I rem out the above
line and open up all the below lines
' Range("A2:G2000").Select
' Selection.Copy
' Windows("Auto_Data.xlsm").Activate
' Sheet2.Select
' Range("B6:H6").Select
' ActiveSheet.Paste
' Selection.AutoFilter
' Application.CutCopyMode = False
' ActiveWindow.ActivateNext
' ActiveWindow.Close
' Range("B4").Select
Application.ScreenUpdating = True
End Sub
【问题讨论】:
-
显示您的代码。您有很多问题没有得到解答,但您的代码会解释这些问题。
-
Edit 你的问题包括你的代码。作为评论无法解读。
-
好的,我想我已经把它贴在那里了。有空的时候请看一下。希望它不会太混乱。谢谢!!
标签: excel vba multiple-columns copy-paste