vba - Excel VBA : Cut a row from one sheet onto another and affix date to the end

标签 vba excel

我正在尝试剪切我在旁边键入 Complete 的行并将其移动到已完成的工作表中。我迷路了,因为我不知道如何将日期添加到它的末尾。理想情况下,我会在 D 列中键入“完成”,并且该行中的 A、B 和 C 单元格将被切换到工作表 2(已完成任务)上的下一行。此外,在 E 列的表 2 上,将添加当前日期。

这是我到目前为止的代码。我不知道如何获得要附加的日期。

Private Sub Worksheet_Change(ByVal Target As Range)
Dim C As Range
If Intersect(Target, Me.Range("D:D")) Is Nothing Then Exit Sub
For Each C In Intersect(Target, Me.Range("D:D")).Cells
If C.Text = "Complete" Then
C.EntireRow.Copy Worksheets("Completed Tasks").Cells(Rows.Count,"C").End(xlUp).Offset(1).EntireRow
  C.Clear
  C.Offset(0, -2).Clear
 End If
 Next
End Sub

谢谢!

最佳答案

这个怎么样?另外,您是否要清除整个 C 行?看起来您只清除了两个 C 行单元格(D 列和 B 列),但我可能是错的。另外,您想删除第一张纸上的整行,以便未完成的任务向上移动到空白处吗?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim C As Range

If Intersect(Target, Me.Range("D:D")) Is Nothing Then Exit Sub

For Each C In Intersect(Target, Me.Range("D:D")).Cells
    If C.Text = "Complete" Then
        C.Offset(0,1).Value = Now 'Adds the date to Column E
        C.Offset(0,1).NumberFormat = ("mm/dd/yyyy") 'Formats the "Now" in a recognizable date way, I assume you are in the US
        C.EntireRow.Copy Worksheets("Completed Tasks").Cells(Rows.Count,"C").End(xlUp).Offset(1).EntireRow
        C.Clear 'Clears Column D?
        C.Offset(0, -2).Clear 'Clears Column B? What about A and C?
    End If
Next C

End Sub

关于vba - Excel VBA : Cut a row from one sheet onto another and affix date to the end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31321085/

相关文章:

mysql - 将 MEMO Ms Jet DB 数据类型转换为 MySql

vba - 如何检查Excel工作表是否包含activeX控件?

list - 动态范围表中的唯一列表,可能有空白

excel - 间接求和

excel - 从 Excel 中最后一个单元格的连接字符串中删除逗号

vba - 使用 VBA,是否有更有效的方法来遍历 Excel 中的行,然后在该循​​环中再循环抛出两次?

vba - 以编程方式将音频文件添加到ppt中的多个幻灯片

excel - 数据透视表计算的字段值不正确

c# - 在功能区中使用 .ico 图像

c# - 设置 Access VBA 的命令行选项