Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Running a macro on cell value change

I have the following code in a worksheet. The first test works perfectly
because the cell C63 is changed by a manual entry. The second test returns a
run-time error "Object required (Error 424)". The cell D9 gets it's value
automatically from another workbook Sheet1 Cell A1 (sic). When I update cell
A1 it does trigger the macro to run run in the worksheet in question (because
the value of D9 has subsequently changed) but it results in the above error.
I actually want to include 4 tests like the second one but I note that if I
change the PrivSub name from Worksheet_Calculate to Worksheet_Calculate_1
then it doesn't trigger at all.

So my two questions are these:
1. What is wrong with the code in Worksheet_Calculate to give the error and
2. What can I call four of these private subs to make them run (or can I
include the four tests in the one Worksheet_Calculate PrivSub)

Thankyou for your time, Brett

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

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


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Running a macro on cell value change

Hi Mike. I figured it out. I had to take out "Intersect(Target," and the
second closing bracket. Now it works like a charm. Thankyou for your help.
Regards, Brett

"Mike" wrote:

Try 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
End Sub

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

"Brettjg" wrote:

I have the following code in a worksheet. The first test works perfectly
because the cell C63 is changed by a manual entry. The second test returns a
run-time error "Object required (Error 424)". The cell D9 gets it's value
automatically from another workbook Sheet1 Cell A1 (sic). When I update cell
A1 it does trigger the macro to run run in the worksheet in question (because
the value of D9 has subsequently changed) but it results in the above error.
I actually want to include 4 tests like the second one but I note that if I
change the PrivSub name from Worksheet_Calculate to Worksheet_Calculate_1
then it doesn't trigger at all.

So my two questions are these:
1. What is wrong with the code in Worksheet_Calculate to give the error and
2. What can I call four of these private subs to make them run (or can I
include the four tests in the one Worksheet_Calculate PrivSub)

Thankyou for your time, Brett

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

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


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Running a macro on cell value change

Check your other thread.

Brettjg wrote:

I have the following code in a worksheet. The first test works perfectly
because the cell C63 is changed by a manual entry. The second test returns a
run-time error "Object required (Error 424)". The cell D9 gets it's value
automatically from another workbook Sheet1 Cell A1 (sic). When I update cell
A1 it does trigger the macro to run run in the worksheet in question (because
the value of D9 has subsequently changed) but it results in the above error.
I actually want to include 4 tests like the second one but I note that if I
change the PrivSub name from Worksheet_Calculate to Worksheet_Calculate_1
then it doesn't trigger at all.

So my two questions are these:
1. What is wrong with the code in Worksheet_Calculate to give the error and
2. What can I call four of these private subs to make them run (or can I
include the four tests in the one Worksheet_Calculate PrivSub)

Thankyou for your time, Brett

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

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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a macro on cell value change Mike Excel Discussion (Misc queries) 0 March 28th 07 01:13 AM
Running a macro on cell value change Brettjg Excel Discussion (Misc queries) 0 March 28th 07 12:08 AM
Running of Worksheet Change Macro breaks undo functionality. Rob Manger Excel Discussion (Misc queries) 1 April 6th 06 04:04 AM
Running a macro in a selected cell... Steve Excel Discussion (Misc queries) 2 January 19th 06 10:58 PM
Macro running when a cell is exited Daniel Lees Excel Discussion (Misc queries) 1 July 20th 05 02:45 PM


All times are GMT +1. The time now is 01:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"