vba - 使用 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
. 不工作。
见下图:第一个粘贴周期以选定的范围结束。我想移动到标记并圈出开始的单元格。这是下一个范围将以与上述相同的方式粘贴的位置,冲洗并重复
解决方案
我试图解决的主要问题是让光标单击粘贴的范围,以便我可以继续。我发现下面的代码很有帮助。这是另一个论坛上的原始帖子: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
推荐阅读
- scala - Spark,如何将 AB,C 转换为 (A, List(B,C))
- r - 如何编写时间循环并给出一个数字
- python - 随机字典选择?
- c - 致命错误:curl/curl.h:没有使用 vcpkg 的文件或目录
- python - 将 PHP POST 请求中的值连接到要执行的 python 脚本中的变量
- java - 没有值的 Java 多键映射
- mysql - 按月选择sql
- php - 如何(通过 Blogger.com)生成一次性动态链接到我的电子书托管@DropBox?
- reactjs - 单击按钮后,如何使用 Reactjs 重定向到带有自动正文和发件人的 Outlook 邮件?
- r - 如何从文章中提取文本下方和上方的关键字