Forum Discussion
Formula
The simplest solution would be to do this manual:
Before clearing column 3, select column 4 and use Copy > Paste Values to preserve the results.
Once the new dividend is known, reapply the formula to column 4.
If to do this manual isn’t an option, you can use VBA.
The VBA approach ensures the formula is automatically managed and results are preserved without manual intervention.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Me ' Refers to the current worksheet
' Check if the changed cell is in column C (Dividend per share)
If Not Intersect(Target, ws.Columns("C")) Is Nothing Then
Dim rng As Range
For Each rng In Target
If IsEmpty(rng.Value) Then
' If the cell in column C is cleared, keep the current value in column D
ws.Cells(rng.Row, "D").Value = ws.Cells(rng.Row, "D").Value
Else
' If a new value is entered, update the formula in column D
ws.Cells(rng.Row, "D").Formula = "=B" & rng.Row & "*C" & rng.Row
End If
Next rng
End If
End SubNote: VBA code is untested, backup your file first.
The VBA macro listens for changes in column 3 (dividend per share).
If you delete a value in column 3, the macro saves the current value in column 4 (total paid) as a static value (no longer linked to the formula).
If you enter a new value in column 3, the macro re-applies the formula in column 4.
My answers are voluntary and without guarantee!
Hope this will help you.