更改特定单元格值时更新特定单元格值

update specific cell value when specific cell value is changed

我对 exel vba 非常陌生,正在学习 vba 我自己的。我有两个单元格范围,分别是 range(j11:j100") 和 range("o11:o100") 两者都只携带日期格式。假设如果我将范围(“J11”)中的日期更改为 1-1-2022 然后自动 相应范围内的日期(“O11”)应该通过添加 28 天来更新,这将是 29-1-2022 这适用于下面的代码但如果我改变 范围内的日期(“j12”)到 2-1-2022 那么相应的范围(“O12”)应该通过添加 28 天来更新,这应该是 30-1-2022,而是 它更新到 29-1-2022

Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rColumn As Range
  Dim tTable As Range
  Set rColumn = Me.Range("j11:J15")
   Set tTable = Me.Range("O11:O15")
   If Not Intersect(Target, rColumn) Is Nothing Then
         If Target.Count = 1 Then
    Intersect(Target.EntireRow, tTable) = Range("J11") + 28
      End If
     End If
  If Not Intersect(Target, Range("J11:J15")) Is Nothing Then
  End If
    End Sub

您总是将 28 天添加到 Range("J11") 中的值而不是更改的单元格,因此将第 8 行更改为:

Intersect(Target.EntireRow, tTable) = Target + 28