Automatic date update in a cell when another cell's value changes (as calculated by a formula)

后端 未结 4 471
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 02:50

I have a formula in C2, say =A2+B2. Whenever C2 changes value (actual value, not formula) I want to have the present date and time updated in D2.

I have

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-17 03:43

    Make the insertion of the date conditional upon the range.

    This has an advantage of not changing the dates unless the content of the cell is changed, and it is in the range C2:C2, even if the sheet is closed and saved, it doesn't recalculate unless the adjacent cell changes.

    Adapted from this tip and @Paul S answer

    Private Sub Worksheet_Change(ByVal Target As Range)
     Dim R1 As Range
     Dim R2 As Range
     Dim InRange As Boolean
        Set R1 = Range(Target.Address)
        Set R2 = Range("C2:C20")
        Set InterSectRange = Application.Intersect(R1, R2)
    
      InRange = Not InterSectRange Is Nothing
         Set InterSectRange = Nothing
       If InRange = True Then
         R1.Offset(0, 1).Value = Now()
       End If
         Set R1 = Nothing
         Set R2 = Nothing
     End Sub
    

提交回复
热议问题