首页 > 解决方案 > 使用 ctrl+shift+down 函数 aka Selection.End(x1down) 进行动态复制和粘贴

问题描述

我正在尝试在两个工作簿之间移动(不同长度的)范围。

Windows("Comp1.xlsx").Activate 'Open sheet to pull data from
Range("E2").Select 'Starting point is the same every time
Range(Selection, Selection.End(xlDown)).Select 'Select all data below
Application.CutCopyMode = False
Selection.Copy 'Copy range
Windows("Comps Proto.xlsm").Activate 'Sheet to be pasted into
Range("K12").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False 'Paste data into new sheet

为了在下一个工作簿中重复这个功能,我需要移除粘贴的选择。我已经尝试了一切,包括偏移量和Application.CutCopyMode = False. 不工作。

见下图:第一个粘贴周期以选定的范围结束。我想移动到标记并圈出开始的单元格。这是下一个范围将以与上述相同的方式粘贴的位置,冲洗并重复

图片

标签: vbaexcel

解决方案


我试图解决的主要问题是让光标单击粘贴的范围,以便我可以继续。我发现下面的代码很有帮助。这是另一个论坛上的原始帖子:https ://superuser.com/questions/342772/how-do-i-move-the-selection-down-one-row-in-excel-2007/342835

Dim ColNumber As Integer

ColNumber = Selection.Column
Range("K" & CStr(ColNumber)).Select 'Click off the pasted values
ActiveCell.End(xlDown).Select 'Equivalent of ctrl+down
ActiveCell.End(xlDown).Select 'Moves down through the range in picture
ActiveCell.Offset(2, 0).Select 'Moves selection to the "Start" point in picture above

推荐阅读