Add a identifier if you change a cell value in a row

时间:2019-04-08 13:19:59

标签: excel vba

Is there a way in excel (VBA) to mark any change in a row (A2-A10) for example with an identifier if any cell in that row is changed. So for if A2 changes, add an X in A1

2 个答案:

答案 0 :(得分:1)

You can have a macro function to change the value or add new value when anything changes in the source cell. This macro will be on the rows where the change needs to be recorded.

答案 1 :(得分:1)

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Count > 1 Then Exit Sub

        Application.EnableEvents = False

        If Not Intersect(Target, Range("A2:A10")) Is Nothing And Target <> "" Then '<- If there is any change in area A2:A10 and the value of the affect cell IS NOT empty then

            ThisWorkbook.Worksheets("Sheet1").Range("A1").Value = "X"

        ElseIf Not Intersect(Target, Range("A2:A10")) Is Nothing And Target = "" Then  '<- If there is any change in area A2:A10 and the value of the affect cell IS empty then

            ThisWorkbook.Worksheets("Sheet1").Range("A1").Value = ""

        End If

        Application.EnableEvents = True

End Sub