首页 > 解决方案 > 循环复制具有特定数据的整行并粘贴到下一行

问题描述

我想要做什么:用户输入一个日期(例如 2021-11-05),对于在 Col A 中与此日期匹配的所有单元格,复制整行并粘贴到下一行。

问题:将第 3 行复制到第 4 行时,第 4 行的日期变为 2021-11-05,然后将第 4 行复制到第 5 行,然后再复制到第 6 行,然后继续。

Sub Macro1()

Dim Myinput As Date
Myinput = InputBox("What is the date you want to copy from?")

Dim cell As Range
Dim rw As Long
For Each cell In Range("A1:A15").Cells
    If cell.Value = Myinput Then
        rw = cell.Row + 1
        cell.EntireRow.Copy
        Range("A" & rw).Activate
        ActiveSheet.Paste
    End If
Next

End Sub

在此处输入图像描述

标签: excelvbavba7

解决方案


推荐阅读