Keeping formulas in excel fields
Keeping formulas in excel fields
(OP)
Hey Excel gods,
is there any way of entering a formula in an excel field, so that if a single entry is made it will override the formula, but if the field is then cleared that the original formula returns. For example : if A1 hold the formula "@sum(F3:F9)" but the user will be able to override this with a value, say the user enters "5" in A1. The next user might not like this and clear the "5". Is it now possible for the field A1 to go back to its original formula of "@sum(F3:F9)"?
Thanks in advance.
Crash
is there any way of entering a formula in an excel field, so that if a single entry is made it will override the formula, but if the field is then cleared that the original formula returns. For example : if A1 hold the formula "@sum(F3:F9)" but the user will be able to override this with a value, say the user enters "5" in A1. The next user might not like this and clear the "5". Is it now possible for the field A1 to go back to its original formula of "@sum(F3:F9)"?
Thanks in advance.
Crash





RE: Keeping formulas in excel fields
prex
motori@xcalcsREMOVE.com
http://www.xcalcs.com
Online tools for structural design
RE: Keeping formulas in excel fields
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.AddressLocal = "$A$1" Then
If Len(Target.Text) > 0 Then
Exit Sub
Else
Target.Formula = "=SUM(F3:F9)"
End If
End If
End Sub
You can also add some additional checking to validate the contents of the cell (i.e. only allow numerical entries).
Hope this helps...
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Keeping formulas in excel fields
user enters a value or puts 0 in cell A1
then A2 is if(A1=0,some formula,A1)
nasty but quick
Cheers
Greg Locock
RE: Keeping formulas in excel fields
Best Regards
Morten
RE: Keeping formulas in excel fields
your code has helped alot. many thanks. Just one more question. it puts the formula result in the the field after the the field is changed to 0. Is there a way of it doing that check when the sheet is made active? I tried using the worksheet_activate event but I get compiling errors if I use that.
Thanks again
RE: Keeping formulas in excel fields
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.AddressLocal = "$A$1" Then
If IsNumeric(Target.Text) = True Then
If Target.Value = 0 Then Exit Sub
ElseIf Len(Target.Text) > 0 Then
Exit Sub
Else
Target.Formula = "=SUM(F3:F9)"
End If
End If
End Sub
As for processing the check upon activating the sheet, use the Worksheet.Activate event to call the Change event:
Private Sub Worksheet_Activate()
Call Worksheet_Change(Range("A1"))
End Sub
Good luck...
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.