提示:其他语言是Google翻译的。 你可以访问 English 版本。
登录
x
or
x
x
注册账户
x

or

如何根据列中的单元格值复制行?

例如,我有一个包含列D中的数字列表的数据范围,现在,我想基于列D中的数值复制整个行多次以获得以下结果。 我怎么能根据Excel中的单元格值多次复制行?

doc通过单元格1复制行

使用VBA代码根据单元格值多次重复行


箭头蓝色右泡 使用VBA代码根据单元格值多次重复行

要根据单元格值多次复制和复制整个行,以下VBA代码可能会帮助您,请按照以下方法操作:

1。 按住 ALT + F11 键打开 Microsoft Visual Basic for Applications 窗口。

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

VBA代码:根据单元格值多次重复行:

Sub CopyData()
'Updateby Extendoffice 20160922
    Dim xRow As Long
    Dim VInSertNum As Variant
    xRow = 1
    Application.ScreenUpdating = False
    Do While (Cells(xRow, "A") <> "")
        VInSertNum = Cells(xRow, "D")
        If ((VInSertNum > 1) And IsNumeric(VInSertNum)) Then
           Range(Cells(xRow, "A"), Cells(xRow, "D")).Copy
           Range(Cells(xRow + 1, "A"), Cells(xRow + VInSertNum - 1, "D")).Select
           Selection.Insert Shift:=xlDown
           xRow = xRow + VInSertNum - 1
        End If
        xRow = xRow + 1
    Loop
    Application.ScreenUpdating = False
End Sub

3。 然后按 F5 键来运行这个代码,整个行根据D列中的单元格值被复制多次。

注意:在上面的代码中,这个字母 A 表示数据范围的起始列和字母 D 是要复制行的基础上的列字母。 请改变他们到您的需要。



推荐的生产力工具

Office Tab

金星1 带上方便的选项卡到Excel和其他Office软件,就像Chrome浏览器,Firefox和新的Internet Explorer。

Kutools for Excel

金星1 惊人! 提高您在5分钟的生产力。 不需要任何特殊技能,每天保存两个小时!

金星1 300 Excel的新功能,让Excel变得简单而强大:

  • 合并单元格/行/列而不丢失数据。
  • 合并和合并多个工作表和工作簿。
  • 比较范围,复制多个范围,将文本转换为日期,单位和货币转换。
  • 按颜色计算,分页小计,高级分类和超级筛选,
  • 更多选择/插入/删除/文本/格式/链接/评论/工作簿/工作表工具...

Excel的Kutools屏幕截图

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.
    ISRA · 28 days ago
    there is any way we can add to eache repeated cell, a consecutive caracters? example
    KTE+0001

    KTE+0002
  • To post as a guest, your comment is unpublished.
    KAS · 2 months ago
    Is there a way to update the module to only duplicate new data? I'm working on an ongoing document and do not want the code to duplicate data that has been previously duplicated.
  • To post as a guest, your comment is unpublished.
    Gerardo Enrique Heras Araujo · 3 months ago
    hi, for me is no working, I want to remove letters and number duplicate is possible?
  • To post as a guest, your comment is unpublished.
    Naomi · 3 months ago
    This script seems to be exactly what I need, however, when I run it I am getting an error on the line Selection.Insert Shift:=x1Down

    Any suggestions on how I fix this?
  • To post as a guest, your comment is unpublished.
    Manuel F · 3 months ago
    Thanks! it has been a great solution for all my troubles!