提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何在Excel中以固定间隔插入特定行数?

在Excel工作表中,您可以使用插入功能在现有行之间插入空白行。 但是,如果您有大量的数据,并且需要在每三行之后插入两行空白行,那么您如何快速方便地完成这项工作?

用VBA代码以固定间隔将特定行数插入数据

使用Kutools for Excel以固定间隔将特定行数插入数据


以固定的时间间隔将特定数量的行或列插入数据中:

Kutools for Excel插入空白行和列 可以帮助您将每隔一行或第n行或列插入现有数据。

DOC  - 插入 - 行 - 值的变化,17

Kutools for Excel:比200方便的Excel加载项,可以在60天免费试用。 下载并免费试用现在!



以下VBA代码可以帮助您在现有数据中的第n行之后插入特定数量的行。 请做如下操作:

1。 按住 ALT + F11 在Excel中的键,它打开 Microsoft Visual Basic for Applications 窗口。

2。 点击 插页 > 模块,并将以下代码粘贴到 模块窗口.

VBA代码:以固定的时间间隔将特定行数插入数据

Sub InsertRowsAtIntervals()
'Updateby20150707
Dim Rng As Range
Dim xInterval As Integer
Dim xRows As Integer
Dim xRowsCount As Integer
Dim xNum1 As Integer
Dim xNum2 As Integer
Dim WorkRng As Range
Dim xWs As Worksheet
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
xRowsCount = WorkRng.Rows.Count
xInterval = Application.InputBox("Enter row interval. ", xTitleId, 1, Type:=1)
xRows = Application.InputBox("How many rows to insert at each interval? ", xTitleId, 1, Type:=1)
xNum1 = WorkRng.Row + xInterval
xNum2 = xRows + xInterval
Set xWs = WorkRng.Parent
For i = 1 To Int(xRowsCount / xInterval)
    xWs.Range(xWs.Cells(xNum1, WorkRng.Column), xWs.Cells(xNum1 + xRows - 1, WorkRng.Column)).Select
    Application.Selection.EntireRow.Insert
    xNum1 = xNum1 + xNum2
Next
End Sub

3. 粘贴此代码后,请按 F5 键来运行这段代码,弹出一个提示框让你选择你想插入空行的数据范围,看截图:

doc以1的间隔插入行

4。 点击 OK 按钮,弹出另一个提示框,请输入行间隔数,参见截图:

doc以2的间隔插入行

5。 继续点击 OK 按钮,在弹出的提示框中,请输入要插入的空白行数,请参阅屏幕截图:

doc以3的间隔插入行

6。 然后点击 OK,并且空行已定期插入到现有数据中,请参见截图:

doc以4的间隔插入行


如果您不熟悉上述VBA代码,Kutools for Excel也可以帮助您,它的插入空白行和列功能可以快速方便地以固定的时间间隔将特定数量的行或列插入到现有数据中。

Kutools for Excel : 与超过300方便的Excel加载项,在60天免费试用没有限制.

安装后 Kutools for Excel请按照以下步骤进行:

1。 选择要间隔插入空行的数据范围。

2。 点击 Kutools > 插页 > 插入空白行和列,看截图:

doc以间隔5 5插入行

3。 在 插入空行和列 对话框中选择 空行 or 空白列 你需要,从 插入类型,然后指定要使用的间隔行数和空行数,如下面的屏幕截图所示:

doc以6的间隔插入行

4。 然后点击 OK 按钮,并且空白行已按照以下屏幕截图以特定间隔插入到所选范围中:

doc以7的间隔插入行

点击了解更多关于此插入空白行和列实用程序。

立即下载并免费试用Kutools for Excel!


Kutools for Excel:比200方便的Excel加载项,可以在60天免费试用。 下载并免费试用现在!


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    PK · 8 months ago
    hi how can I get the code for Insert specific number of columns into data at fixed intervals
    • To post as a guest, your comment is unpublished.
      skyyang · 8 months ago
      Hello, PK,
      To insert blank columns into existing data at specific intervals, the below VBA code can help you! Please try it.

      Sub InsertColumnsAtIntervals()
      Dim Rng As Range
      Dim xInterval As Integer
      Dim xCs As Integer
      Dim xCCount As Integer
      Dim xNum1 As Integer
      Dim xNum2 As Integer
      Dim WorkRng As Range
      Dim xWs As Worksheet
      xTitleId = "KutoolsforExcel"
      Set WorkRng = Application.Selection
      Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
      xCCount = WorkRng.Columns.Count
      xInterval = Application.InputBox("Enter column interval. ", xTitleId, 1, Type:=1)
      xCs = Application.InputBox("How many columns to insert at each interval? ", xTitleId, 1, Type:=1)
      xNum1 = WorkRng.Column + xInterval
      xNum2 = xCs + xInterval
      Set xWs = WorkRng.Parent
      For I = 1 To Int(xCCount / xInterval)
      xWs.Range(xWs.Cells(WorkRng.Row, xNum1 + xCs - 1), xWs.Cells(WorkRng.Row, xNum1)).Select
      Application.Selection.EntireColumn.Insert
      xNum1 = xNum1 + xNum2
      Next
      End Sub
  • To post as a guest, your comment is unpublished.
    Martin · 1 years ago
    Fantastic - you saved me a lot of mindless data entry, thank you very much
  • To post as a guest, your comment is unpublished.
    Manish · 1 years ago
    Hi


    I use interval vba code its working..But when I use above 100000 rows it not working.. kindly suggest what should I change if any.


    Sub InsertRowsAtIntervals()
    'Updateby20150707
    Dim Rng As Range
    Dim xInterval As Integer
    Dim xRows As Integer
    Dim xRowsCount As Integer
    Dim xNum1 As Integer
    Dim xNum2 As Integer
    Dim WorkRng As Range
    Dim xWs As Worksheet
    xTitleId = "KutoolsforExcel"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    xRowsCount = WorkRng.Rows.Count
    xInterval = Application.InputBox("Enter row interval. ", xTitleId, 1, Type:=1)
    xRows = Application.InputBox("How many rows to insert at each interval? ", xTitleId, 1, Type:=1)
    xNum1 = WorkRng.Row + xInterval
    xNum2 = xRows + xInterval
    Set xWs = WorkRng.Parent
    For i = 1 To Int(xRowsCount / xInterval)
    xWs.Range(xWs.Cells(xNum1, WorkRng.Column), xWs.Cells(xNum1 + xRows - 1, WorkRng.Column)).Select
    Application.Selection.EntireRow.Insert
    xNum1 = xNum1 + xNum2
    Next
    End Sub
  • To post as a guest, your comment is unpublished.
    Atif · 2 years ago
    Thanks AloT!!
  • To post as a guest, your comment is unpublished.
    Stephanie · 2 years ago
    thank you so much!!!!! this is amazing
  • To post as a guest, your comment is unpublished.
    Farooq · 2 years ago
    Hi,

    I'm using your code (below) can you please tell me how can fill those rows with custom text into it. I've used your code to enter three rows it worked perfectly but now I need to enter the text

    Row1 = Date
    Row2.= Location
    Row3 = Phone Number

    Thanks in advance...



    "Sub InsertRowsAtIntervals()
    'Updateby20150707
    Dim Rng As Range
    Dim xInterval As Integer
    Dim xRows As Integer
    Dim xRowsCount As Integer
    Dim xNum1 As Integer
    Dim xNum2 As Integer
    Dim WorkRng As Range
    Dim xWs As Worksheet
    xTitleId = "KutoolsforExcel"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    xRowsCount = WorkRng.Rows.Count
    xInterval = Application.InputBox("Enter row interval. ", xTitleId, 1, Type:=1)
    xRows = Application.InputBox("How many rows to insert at each interval? ", xTitleId, 1, Type:=1)
    xNum1 = WorkRng.Row + xInterval
    xNum2 = xRows + xInterval
    Set xWs = WorkRng.Parent
    For i = 1 To Int(xRowsCount / xInterval)
    xWs.Range(xWs.Cells(xNum1, WorkRng.Column), xWs.Cells(xNum1 + xRows - 1, WorkRng.Column)).Select
    Application.Selection.EntireRow.Insert
    xNum1 = xNum1 + xNum2
    Next
    End Sub"