插入特定行数 [英] Insert Specific Number of Rows

查看:74
本文介绍了插入特定行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试插入特定数量的行.现在我正在使用下面的代码插入 4 行.我正在尝试编写一行代码,根据特定单元格中的数字插入特定数字或行.例如,如果我想插入 4 行,而单元格 A2 是我可以更改要添加的行数的单元格,我将使用什么代码根据我在单元格 A2 中插入的数字来添加任意数量的行.

I'm trying to insert a specific number of rows. Right now I'm using the below code to insert 4 lines. I'm trying to write a line of code that will insert a certain number or rows based on a number in a certain cell. For example, if I wanted to insert 4 rows and cell A2 is the cell where I can change the number of rows I want to add, what code would I use to add any number of rows based off what number I insert in cell A2.

ActiveCell.EntireRow.Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown

推荐答案

您可以使用类似下面一行的内容一次插入 4 行:

You can use something like the line below to insert 4 rows at once:

ActiveCell.EntireRow.Resize(4).Insert Shift:=xlDown 

或者可能是下面的行(取决于您希望添加行的位置):

or maybe the line below (depends on where you want the added rows to be added):

ActiveCell.EntireRow.Offset(1).Resize(4).Insert Shift:=xlDown

并且无需使用 ActiveCell ,这是始终推荐的:

and without the need to use ActiveCell , which is always recommended:

Range("A2").EntireRow.Offset(1).Resize(4).Insert Shift:=xlDown

这篇关于插入特定行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆