【发布时间】:2016-06-28 18:05:32
【问题描述】:
我正在尝试仅使用击键来录制宏,但在最后一次击键时遇到了问题,因为它没有达到我的预期。我正在做的一些背景知识 - 我正在使用不断增长的数据和滚动图来绘制最后 4 行数据。我正在尝试从一张表中复制数据并将其粘贴到另一张表中的下一个空行中。因为我正在使用击键,所以我希望宏记录点击次数,但这不是它正在做的事情。相反,它将数据粘贴在记录宏的确切单元格上,而不是其下方的空单元格上。例如,我已经在 C19 中有数据。当我运行宏时,我希望它将新数据粘贴到 C20 中,但它粘贴在 C19 上。我想我需要添加/编辑我的 VBA,以便它将新数据粘贴到另一个工作表的下一个空行中。我希望这是有道理的。任何帮助都感激不尽!
谢谢!!
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
Range("C3").Select
ActiveCell.FormulaR1C1 = "=DATE(YEAR(RC[-1]), MONTH(RC[-1])+1, DAY(RC[-1]))"
Range("C3").Select
Selection.Copy
Range("B3").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("C3").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("B85:K146").Select
Selection.Copy
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
Range("B9").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
ActiveSheet.Next.Select
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
Range("E71:G71").Select
Application.CutCopyMode = False
Selection.Copy
Range("A1").Select
ActiveSheet.Next.Select
Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
Selection.End(xlToLeft).Select
Selection.End(xlUp).Select
Selection.End(xlUp).Select
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
Selection.End(xlToRight).Select
Selection.End(xlToLeft).Select
Range("C5").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("C19").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
结束子
【问题讨论】:
-
using keystrokes only请不要那样做。编辑:使用逻辑并以这种方式编码 ^_^ -
另外,在您尝试解决主要代码问题之前,请通读How to avoid using
.Select。这是一个很好的起点,特别是如果您使用宏记录器。您很快就会看到,您的很多代码都可以直接删除。学习直接处理数据。