I have a little forecast tool that allows people to make changes to a forecast to see the expected result. When a change is made, I have code that reveals a button to reset the formulas when the user is ready, pasted below. I have a formula in cell E5 that checks to see if several other cells are formulas. When they are not formulas, my E5 value changes to 1, and the button appears. Clicking on the button runs a macro that restores the formulas.
My problem is that when ANY OTHER spreadsheet is open, this code errors out. It tries to run no matter what sheet is being changed. The code should ONLY run when a change is made on a tab labeled "DENOM FORECAST." I've tried to limit it to just that tab, to no avail.
Can this code be modified to limit when it executes, or is there another way to show and hide a button when a value on a sheet changes?
My problem is that when ANY OTHER spreadsheet is open, this code errors out. It tries to run no matter what sheet is being changed. The code should ONLY run when a change is made on a tab labeled "DENOM FORECAST." I've tried to limit it to just that tab, to no avail.
Can this code be modified to limit when it executes, or is there another way to show and hide a button when a value on a sheet changes?
VBA Code:
Private Sub Worksheet_Calculate()
Static OldVal As Variant
If Range("E5").Value <> OldVal Then
OldVal = Range("E5").Value
End If
If OldVal = 0 Then
Worksheets("Denom Forecast").Shapes("ResetButton").Visible = False
Else:
Worksheets("Denom Forecast").Shapes("ResetButton").Visible = True
End If
End Sub
'Private Sub Worksheet_Change(ByVal Target As Range)
' If Target.Row = 5 And Target.Column = 5 Then _
' Me.Shapes("ResetButton").Visible = (Cells(5, 5).Value = 1)
'End Sub