Hello, I am trying to write some code that will calculate the days between two dates if cell in column "A" is populated. Currently i have this bit (if A is populated, Q(offset 16) should equal the difference between N(offset 13) and P(offset 15):
The problem is that it works for the first row and then excel freezes. Few things to note:
* code is in Private Sub Worksheet_Change(ByVal Target As Range)
* dates in cells i want to find difference are populated by VBA based on conditions (drop down menu), i want to be able to edit them manually (i can) and the result to auto calculate as well, not just by the condition
* i have Application.Calculation = xlCalculationAutomatic at start of the Sub
I am not very good with VBA and i have written lots of other code there, that might cause any trouble, but without this bit above, everything works fine. Can provide the whole file if needed. Thanks in advance
Code:
Dim cell As Range
For Each cell In Range("A3:A100")
If Not IsEmpty(cell) Then
cell.Offset(, 16).Value = DateDiff("d", cell.Offset(, 13), cell.Offset(, 15))
End If
Next
The problem is that it works for the first row and then excel freezes. Few things to note:
* code is in Private Sub Worksheet_Change(ByVal Target As Range)
* dates in cells i want to find difference are populated by VBA based on conditions (drop down menu), i want to be able to edit them manually (i can) and the result to auto calculate as well, not just by the condition
* i have Application.Calculation = xlCalculationAutomatic at start of the Sub
I am not very good with VBA and i have written lots of other code there, that might cause any trouble, but without this bit above, everything works fine. Can provide the whole file if needed. Thanks in advance