复制单元格范围和粘贴到第一个空行更有效的代码?高强 [英] copying range of cells and pasting to the first empty row more effective code? Excel
问题描述
Sub Macro5()
/ pre>
范围(A3:J3)选择
范围(选择,选择
Selection.Copy
表格(过去搜索)选择
范围(A1)。End(xlDown).Offset(1,0 )。选择
ActiveSheet.Paste
工作表(新建搜索)。激活
Application.CutCopyMode = False
End Sub
解决方案首先,您不必使用。选择或。激活您将操纵的单元格/工作表只需直接引用它们。这样可以减慢你的代码。
.Copy方法可以使用Destination参数,因此您不必在其他地方使用.Paste。
此外,.End属性不是很可靠。最好使用UsedRange代替。
你可以在只有一行中做到这一点。
Worksheets(New Search)。Range(A3:J3)。复制目的地:=工作表(过去搜索)UsedRange.Columns(1).Offset(1,0)
I have a Macro that takes a selection of cells from "New Search" and paste the range to the first open cell in "Past Searches" I'm thinking that my code is very ineffective. Does anyone have any ideas of how I can improve this?
Sub Macro5() Range("A3:J3").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Sheets("Past Searches").Select Range("A1").End(xlDown).Offset(1, 0).Select ActiveSheet.Paste Worksheets("New Searches").Activate Application.CutCopyMode = False End Sub
解决方案First, you don't have to use .Select or .Activate on cells/worksheets that you'll manipulate, just reference them directly. That can really slow down your code.
The .Copy method can take a Destination parameter, so you don't have to use .Paste somewhere else.
Also, the .End property isn't very reliable. It's better to use UsedRange instead.
You can do that pretty much in only 1 line.
Worksheets("New Search").Range("A3:J3").Copy Destination:=Worksheets("Past Searches").UsedRange.Columns(1).Offset(1, 0)
这篇关于复制单元格范围和粘贴到第一个空行更有效的代码?高强的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!