【问题标题】:Paste rows into next empty row将行粘贴到下一个空行
【发布时间】:2019-02-27 00:14:58
【问题描述】:

我正在尝试剪切带有“已部署”一词的状态列的行,并将它们粘贴到名为“已部署”的新工作表中。我需要将这些行粘贴到下一个空行中,这样“已部署”工作表上的现有行就不会被复制。

每次marco 运行时,我都开始重新格式化“已部署”工作表的代码,但被告知我需要保留所有数据并添加到其中,现在我被卡住了。我在网上找不到任何地方如何做到这一点。

这是我需要更改以复制到下一个可用空行而不是第 2 行的代码。请帮忙!

Sub CutRows() 'cuts all rows with status deployed into the Deployed worksheet - working
    Dim cell As Range
    Dim lastRow As Long
    Dim i As Long
    Set Wksh1 = Worksheets("01 Feb 19")
    Set Wksh2 = Worksheets("Deployed")

    lastRow = Wksh1.Range("A" & Rows.Count).End(xlUp).Row 'finds the last row

    i = 2 ' copies onto wksh2 row 2

    For Each cell In Wksh1.Range("T1:T" & lastRow) 'looks in T column until the last row (loop)
        If cell.Value = "Deployed" Then 'searches for word deployed
            cell.EntireRow.Cut Wksh2.Cells(i, 1) 'cuts entire row into Deployed worksheet
            i = i + 1 'Added so that rows don't overwrite each other
        End If
    Next cell 'To close the cell loop (For loop)
End Sub

【问题讨论】:

标签: excel vba


【解决方案1】:

只需将i = 2 替换为i = Wksh2.Range("A" & Wksh2.Rows.Count).End(xlUp).Row + 1

【讨论】:

  • 漂亮,现在我看到了,这很有意义!谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-06
  • 2019-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多