Data Validation in Calculated Cells - P.S.
"Bernie Deitrick" <deitbe @ consumer dot org wrote...
Greg,
This will completely undo the entry:
Private Sub Worksheet_Change(ByVal Target As Range)
....
Application.Undo 'Optional undo
....
The cleverer users may figure out something like
C2:
=IF(foo,A2+B2,ROW())
Enter this formula with the defined name foo equal to FALSE, and the
formulas would be accepted. Then change foo to TRUE. Recalculation
doesn't trigger Change event handlers. To make this robust, you'd need
to use Calculate handlers too.
But that begs the question how to ensure users don't turn off macros
entirely or the cleverer ones disable event handlers.
If the OP just wants to flag duplicate values arising from sums of
cols A and B in col C (e.g., C2: =A2+B2), then conditional formatting
would be most appropriate - AND it works whether macros are enabled or
disabled. Make the conditions formulas like
C1:
=COUNTIF(C2:C$45000,C1)0
C2:
=COUNTIF(C$1:C1,C2)+COUNTIF(C3:C$45000,C2)0
Fill C2 down into C3:C44999
C45000:
=COUNTIF(C$1:C44999,C45000)0
and set an appropriate format, like red cell background color. Add a
formula in another cell to check that the count of distinct values in
col C equals the count of all values in col C, and use that to
determine whether the formulas are valid or not.
|