【发布时间】:2019-03-05 08:59:26
【问题描述】:
谁能帮我调整这段代码来修复我的解决方案?
我有一个按钮,可以从 A5 向下添加 x 数量的新行。 A - Z 列。
我希望新行为空白,但仍包含下拉菜单和公式。 VBA 新手,正在为此苦苦挣扎。
我想我需要更改范围并添加 xlPasteFormulas 但不确定两者的位置和方式。非常感谢任何帮助。
Option Explicit
Sub AddRows()
Dim x As Integer
x = InputBox("How many rows would you like to add?", "Insert Rows")
'Selecting range to insert new cells
Range(Cells(5, 1), Cells(x + 4, 1)).EntireRow.Insert
'Copys current cell A6 and past in the new cells
Cells(x + 5, 1).Copy Range(Cells(5, 1), Cells(x + 4, 1))
'if you want the cells to be blank but still have the drop down options
Range(Cells(5, 1), Cells(x + 4, 1)).ClearContents
End Sub
【问题讨论】:
-
你昨天发过这个吗?我添加了一条评论,您只复制了 1 个单元格。
Cells(x + 5, 1).Copy -
是的,对不起。我尝试增加范围,但我不确定如何并且不断出现错误。我将如何将其更改为复制 A5:A26。我今天午餐时间有一个关于这本工作簿的演示文稿。
-
看看/做一些研究,例如
cells。您只使用Cells(x + 5,1).Copy复制 1 行会放弃它,从哪里开始。 :o)
标签: excel vba button row formula