I have a worksheet that is protected, so users can only enter data in certain cells. I want to be able to detect when a cell is changed and run a macro that uses GoalSeek to perform a calculation.
The sheet is unprotected during the calculation, data from a cell is placed in a "holding cell", the calculation is performed and the result is stored in another cell, and then the original data is replaced.
Here's the code I have in place. My problem is that it either doesn't detect the change and so doesn't calculate, or it does and gets caught in an endless loop. I added several unprotects because it seems to re-protect the sheet (maybe due to another macro).
Private Sub Worksheet_Change(ByVal Target As Range)
Calculate
ActiveSheet.Unprotect
Range("A243").Value = Range("B135").Value
Range("D171").GoalSeek Goal:=10000, ChangingCell:=Range("B135")
ActiveSheet.Unprotect
Range("B243").Value = Range("B135").Value
ActiveSheet.Unprotect
Range("B135").Value = Range("A243").Value
ActiveSheet.Unprotect
Range("C185:D185").Value = Range("C243").Value
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Calculate
End Sub
Thank you in advance for your help.