繁体   English   中英

Excel宏为行中的任何数据更改添加日期

[英]Excel macro to add date for any change in data in a row

我希望解析特定excel工作表中的整个行,以获取该行中数据的任何更改。 如果该行中的数据有任何更改,那么我想添加该行中该特定单元格的日期。 我想将该行作为输入传递。 我尝试了以下代码,但没有用。


Private Function User_func1(ByVal i As Long)

    Dim j As Long

    For j = 1 To j = 100
        If Cells(i, j).Value > 1 Then
            Cells(i, 2) = Now()
        End If
    Next j

End Function

您可以在要扫描的Worksheet_Change中使用Worksheet_Change事件。

Option Explicit

Const RowtoTest = 2

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
If Target.Row = RowtoTest Then
    Target.Value = Date
End If
Application.EnableEvents = True

End Sub

选项2 :从某个单元格获取要测试的行,假设单元格为“ A1”(值设置为2,表示在第2行的单元格中查找更改)。

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
' compare the row number to the number inputted as the row to test in cell A1
If Target.Row = Range("A1").Value Then
    Target.Value = Date
End If
Application.EnableEvents = True

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM