Preserving Previous Formula Values
One method would be to use the Sheet's CHANGE event
taht's fired whenever a value is entered. The code below
should be pasted to the sheet's code page - right click
the sheet tab & goto View Code
The code is tests to see if the cell that has changed is
in the column U10:U30
If it is then the value is calculated an paced in cell X
of the same row/ So enter a value in U25 then X25 will
get the value from the formula.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rw As Long
rw = Target.Row
' test target column
If Target.Column = 21 Then '"h"
' test if its a 'month'
If rw = 19 And rw <= 30 Then
Cells(rw, "X").Value = _
(Target.Value - Range("V10").Value) / _
(Range("P10").Value - Range("V10").Value)
End If
End If
End Sub
NOTE The values in P10 and V10 will be used by the code,
so they must be entered BEFORE the value in U
Patrick Molloy
Microsoft Excel MVP
-----Original Message-----
The "X" cell formulas below return a value based on
entries in cells U19 through U30 (12 months of a year).
The values for V10 and P10 may also change each month.
This system works fine for the immediate month being
posted; however, it returns a false history for previous
months, due to the changes in V10 and P10. I have to
maintain a history of the values returned in the "X"
cells - that is, once a value is entered in, say, U20,
the
value in X19 (the previous month) is preserved -
regardless of new values entered in V10 and P10. Also,
if
the user deletes an entry for a current month, the
formula
works as before - as though no entry was ever made -
kind
of a built-in undo.
There are 48 yearly ranges involved in this reporting
system, so I'm not sure if this is a cell formula or
module coding issue.
Is this possible? If so could someone help me through
the
code?
Cell Formula
X19 =IF(U19="","",IF(U19<0,(U19-V10)/(P10-V10),0))
X20 =IF(U20="","",IF(U20<0,(U20-V10)/(P10-V10),0))
X21 =IF(U21="","",IF(U21<0,(U21-V10)/(P10-V10),0))
Etc.
X30 =IF(U30="","",IF(U30<0,(U30-V10)/(P10-V10),0))
.
|