I have a code that changes a cell value when a certain range is changed. When I manually change a value in that range the code works just fine. But when a value in that range is changed by a formula the cell which needs to be changed is not updating. Is it possible to let excel see when a formula changes cell value, so my code that changes a cell value works.
This is my code:
Dim KeyCells As Range
' The variable KeyCells contains the cells that will change by user
Set KeyCells = Workbooks(Projectplanner).Sheets("Planning").Range("B9:C13,10:10")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
'Set value of cell E4 to 1 when values in KeyCells has been changed
Workbooks(Projectplanner).Sheets("Planning").Range("A7").Value = 1
EDIT after replies:
Private Sub Worksheet_Calculate()
'| Define current projectplanner
Dim Projectnumber As String
Projectnumber = ActiveWorkbook.Sheets("Planning").Range("A6").Value2
Dim Projectplanner As String
Projectplanner = Projectnumber & ".xlsm"
If Range("Employe1").Value <> PrevVal1 Then
Workbooks(Projectplanner).Sheets("Planning").Range("Employe1").Offset(0, 1).Value = 1
PrevVal1 = Range("Employe1").Value
End If
If Range("Employe2").Value <> PrevVal2 Then
Workbooks(Projectplanner).Sheets("Planning").Range("Employe2").Offset(0, 1).Value = 1
PrevVa2 = Range("Employe2").Value
End If
If Range("Employe3").Value <> PrevVal3 Then
Workbooks(Projectplanner).Sheets("Planning").Range("Employe3").Offset(0, 1).Value = 1
PrevVal3 = Range("Employe3").Value
End If
and so on and so on for 19 ranges.