Excel 如何多次复制和插入行或复制行X次 您所在的位置:网站首页 excel表多行复制 Excel 如何多次复制和插入行或复制行X次

Excel 如何多次复制和插入行或复制行X次

2023-03-12 23:58| 来源: 网络整理| 查看: 265

Excel 如何多次复制和插入行或复制行X次

如果我们想在Excel中复制表格中的现有行,当我们手动操作时,那么它可能是一个耗时的过程,因为我们需要插入和复制值。我们可以使用VBA程序来自动完成这个过程。

阅读本教程,了解如何在Excel中多次复制和插入一行,或将该行复制 “X “次。在这里,我们将首先插入VBA模块,然后运行代码来完成任务。让我们来看看在Excel中多次复制和插入一行或复制一行 “X “次的简单程序。

第1步

让我们考虑一个Excel工作表,它有一个类似于下面的表格。

如何在Excel中多次复制和插入行或复制行X次?

打开VBA应用程序,点击插入,选择查看代码,点击插入,选择模块,然后在文本框中输入下面提到的程序1,如下图所示。

程序1 Sub test() 'Update By Nirmal Dim xCount As Integer LableNumber: xCount = Application.InputBox("Number of Rows", "Duplicate the rows", , , , , , 1) If xCount < 1 Then MsgBox "the entered number of rows is error, please enter again", vbInformation, "Select the values" GoTo LableNumber End If ActiveCell.EntireRow.Copy Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(xCount, 0)).EntireRow.Insert Shift:=xlDown Application.CutCopyMode = False End Sub 第2步

现在将工作表保存为支持宏的工作表,点击你要复制的数值,然后点击F5,选择你要复制的次数,并点击确定。

如何在Excel中多次复制和插入行或复制行X次?

如果我们想复制整个行,我们可以用程序2代替程序1

程序2 Sub insertrows() 'Update By Nirmal Dim I As Long Dim xCount As Integer LableNumber: xCount = Application.InputBox("Number of Rows", "Duplicate whole values", , , , , , 1) If xCount < 1 Then MsgBox "the entered number of rows is error ,please enter again", vbInformation, "Enter no of times" GoTo LableNumber End If For I = Range("A" & Rows.CountLarge).End(xlUp).Row To 2 Step -1 Rows(I).Copy Rows(I).Resize(xCount).Insert Next Application.CutCopyMode = False End Sub 总结

在本教程中,我们用一个简单的例子来演示如何在Excel中多次复制和粘贴一行或一列。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有