ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Run macro if cell value changes (https://www.excelbanter.com/excel-discussion-misc-queries/136333-re-run-macro-if-cell-value-changes.html)

Brettjg

Run macro if cell value changes
 
Hey GS, thankyou for that. Do you mean like this (cos the second one still
doesn't work with this):

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C63")) Is Nothing Then
Application.EnableEvents = False
Application.Run "Calculate_Stamp_Duty_NEW_HOME"
Application.EnableEvents = True
End If

If Not Intersect(Target, Range("D9")) Is Nothing Then
Application.EnableEvents = False
Application.Run "Calculate_Stamp_Duty_PROPERTY_3"
Application.EnableEvents = True
End If

End Sub


Gary''s Student

Run macro if cell value changes
 
More like two separate macros:

Private Sub Worksheet_Calculate()
If Not Intersect(Target, Range("D9")) Is Nothing Then
Application.EnableEvents = False
Application.Run "Calculate_Stamp_Duty_PROPERTY_3"
Application.EnableEvents = True
End If
End Sub




Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C63")) Is Nothing Then
Application.EnableEvents = False
Application.Run "Calculate_Stamp_Duty_NEW_HOME"
Application.EnableEvents = True
End If
End Sub

--
Gary''s Student
gsnu200712


Brettjg

Run macro if cell value changes
 
Well, we are getting there. With the following code the macro does get
triggered when I change the other workbook, but it gets a run time error of
"Object required (Error 424)"

Private Sub Worksheet_Calculate()
If Not Intersect(Target, Range("D9")) Is Nothing Then
Application.EnableEvents = False
Application.Run "Calculate_Stamp_Duty_PROPERTY_3"
Application.EnableEvents = True
End If
End Sub

Not being completely lazy, I did check the Help, but I don't understand it
(as I don't with justabout all VB help!). This is where I'm a bit dopey, you
see. I didn't even realise you could have two Private Subs in the one
worksheet. The other question is: I need to actually have 4 of these macros
in the sheet. I tried
Private Sub Worksheet_Calculate_1()

Private Sub Worksheet_Calculate_2()
etc but obviously the name of the PS is important because they didn't
trigger any action.

Thanks for your help so far, I think we've (you've?) nearly done it.
Regards Brett.




All times are GMT +1. The time now is 05:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com