bergie7isu
New Member
- Joined
- Dec 1, 2010
- Messages
- 14
Long time browser, first time poster.
I've got a problem with a worksheet change event being triggered after I manually run a macro. The issue is that the change event actually happens before the manually run macro is even started. I've duplicated the issue in a much simpler example. Code below.
So, in this simplified example, I've got a "Calc" button that runs a macro to sum the values of three cells (A1, A2, and A3) and output the result to A5. My worksheet change event handler clears the value out of A5 if any of the values in the input cells are changed. Everything works fine until I change the value of one of the input cells but don't hit enter or click into a different cell before clicking the "Calc" button. In that scenario, the macro recognizes the new value I put into the cell (and calculates the correct sum...which I know by throwing a quick msgbox into the calc macro), but the result doesn't show in A5 because it's cleared by the change event handler. It's like the change event that was started before I ran the macro doesn't actually complete until after the macro runs...except the macro does recognize that the input values changed.
Anybody know how I can get around this?
Thanks!
I've got a problem with a worksheet change event being triggered after I manually run a macro. The issue is that the change event actually happens before the manually run macro is even started. I've duplicated the issue in a much simpler example. Code below.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A3")) Is Nothing Then
Range("A5").ClearContents
End If
End Sub
Sub calc()
Range("A5") = Range("A1") + Range("A2") + Range("A3")
End Sub
So, in this simplified example, I've got a "Calc" button that runs a macro to sum the values of three cells (A1, A2, and A3) and output the result to A5. My worksheet change event handler clears the value out of A5 if any of the values in the input cells are changed. Everything works fine until I change the value of one of the input cells but don't hit enter or click into a different cell before clicking the "Calc" button. In that scenario, the macro recognizes the new value I put into the cell (and calculates the correct sum...which I know by throwing a quick msgbox into the calc macro), but the result doesn't show in A5 because it's cleared by the change event handler. It's like the change event that was started before I ran the macro doesn't actually complete until after the macro runs...except the macro does recognize that the input values changed.
Anybody know how I can get around this?
Thanks!