Iam very new to exel vba studing vba my own. I have a two cell ranges that is range(j11:j100") and range("o11:o100") both carrying date format only. suppose if i change a date in range("J11") to 1-1-2022 then automatically date in the corresponding range("O11") should update by adding 28 days to it which will be 29-1-2022 which works fine with below code but if i change date in range("j12") to 2-1-2022 then the corresponding range("O12") should update by adding 28 day to it which should be 30-1-2022, but instead it updates to 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
CodePudding user response:
You're always adding 28 days to the value in Range("J11")
instead of changed cell, so change the 8th line to:
Intersect(Target.EntireRow, tTable) = Target 28