Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default When I change a cell a macro will autorun BUT..


I initially posted a thread on *"How do get a macro to autorun when i
change a cell in the spreadsheet?"*

Ok, here come the problem now, I replicated this worksheet in the same
workbook to do another analysis. Now i have 2 worksheets namely
CountryA and CountryB (Copied via using create copy of worksheet).

So when I change the cell in CountryA, the macro is also running
CountryB. The Cell which I change is actually a Validation list of
"Purchase" and "Sales". I change it let's say from Purchase to Sales.
It goes to the CountryB worksheet and runs the macro???

Why is this *Private Sub Worksheet_Change(ByVal Target As Range)* also
performing the macro on CountryB worksheet?

How can make sure that it is only running for CountryA when I change
the cell in this worksheet?

Is it something wrong i did?

Please help... and Thanks in advance

Below was the reply that i have got previously


Formula:
--------------------
Question : Let say Cell "A1" has only 2 values that is Purchase or Sales.
Now when i change this cell to either value, i want it to run a macro
e.g. When i change Cell to "Purchase" i want to autorun Macro A and When i change Cell to "Sales" i want to autorun Macro B. How do i do this? And it is for a particular worksheet only.

JIM THOMLINSON
Right click the tab of the sheet containing the ceel with purchase and sale
in Cell A1 then select view code... Paste the following.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
If Target.Value = "Purchase" Then Call Macro1
If Target.Value = "Sales" Then Call Macro2
End If
End Sub

MUDRAKER
You need to use the worksheet change event
This goes in the module for the particular worksheet that you want to trigger the macro

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
Application.EnableEvents = False
Select Case Target.Value
Case "Purchase"
Call macroA
Case "Sales"
Call MacroB
End Select
End If
Application.EnableEvents = True
End Sub
--------------------


--
Infinity
------------------------------------------------------------------------
Infinity's Profile: http://www.excelforum.com/member.php...o&userid=32725
View this thread: http://www.excelforum.com/showthread...hreadid=527970

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default When I change a cell a macro will autorun BUT..

If the sheetA code changes something on sheetB then that will trigger the
sheetB code to run.

Try disabling events before running the sheet code: re-enable at the end

'***********************
application.enableevents=false
'do stuff
application.enableevents=true
'***********************

Tim

"Infinity" wrote in
message ...

I initially posted a thread on *"How do get a macro to autorun when i
change a cell in the spreadsheet?"*

Ok, here come the problem now, I replicated this worksheet in the same
workbook to do another analysis. Now i have 2 worksheets namely
CountryA and CountryB (Copied via using create copy of worksheet).

So when I change the cell in CountryA, the macro is also running
CountryB. The Cell which I change is actually a Validation list of
"Purchase" and "Sales". I change it let's say from Purchase to Sales.
It goes to the CountryB worksheet and runs the macro???

Why is this *Private Sub Worksheet_Change(ByVal Target As Range)* also
performing the macro on CountryB worksheet?

How can make sure that it is only running for CountryA when I change
the cell in this worksheet?

Is it something wrong i did?

Please help... and Thanks in advance

Below was the reply that i have got previously


Formula:
--------------------
Question : Let say Cell "A1" has only 2 values that is Purchase or
Sales.
Now when i change this cell to either value, i want it to run a macro
e.g. When i change Cell to "Purchase" i want to autorun Macro A and When
i change Cell to "Sales" i want to autorun Macro B. How do i do this? And
it is for a particular worksheet only.

JIM THOMLINSON
Right click the tab of the sheet containing the ceel with purchase and
sale
in Cell A1 then select view code... Paste the following.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
If Target.Value = "Purchase" Then Call Macro1
If Target.Value = "Sales" Then Call Macro2
End If
End Sub

MUDRAKER
You need to use the worksheet change event
This goes in the module for the particular worksheet that you want to
trigger the macro

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
Application.EnableEvents = False
Select Case Target.Value
Case "Purchase"
Call macroA
Case "Sales"
Call MacroB
End Select
End If
Application.EnableEvents = True
End Sub
--------------------


--
Infinity
------------------------------------------------------------------------
Infinity's Profile:
http://www.excelforum.com/member.php...o&userid=32725
View this thread: http://www.excelforum.com/showthread...hreadid=527970



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default When I change a cell a macro will autorun BUT..


Sorry, but i still dont understand . I am not very good a
macro.

Would appreciate very much if you could give me an example.

Thanks... thanks.. thanks...:

--
Infinit
-----------------------------------------------------------------------
Infinity's Profile: http://www.excelforum.com/member.php...fo&userid=3272
View this thread: http://www.excelforum.com/showthread.php?threadid=52797

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default When I change a cell a macro will autorun BUT..


WTF??

Sometimes it is working, sometimes it is not working...
*FRUSTRATED* :

--
Infinit
-----------------------------------------------------------------------
Infinity's Profile: http://www.excelforum.com/member.php...fo&userid=3272
View this thread: http://www.excelforum.com/showthread.php?threadid=52797

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default When I change a cell a macro will autorun BUT..

Typo:

If Target.Value = "Purchase" Then Call Macro1
If Target.Value = "Sales" Then Call Macro2
Application.EnableEvents=True


--
Tim Williams
Palo Alto, CA


"Tim Williams" wrote in message
oups.com...
Without knowing the exact code you're using it's difficult to suggest
anything else.

The modification to Jim's code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Application.EnableEvents=false
If Target.Value = "Purchase" Then Call Macro1
If Target.Value = "Sales" Then Call Macro2
Application.EnableEvents=false
End If
End Sub


WTF??


Sometimes it is working, sometimes it is not working....
*FRUSTRATED* :(



--
Infinity






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default When I change a cell a macro will autorun BUT..


Thanks.... :) Will test it out today....


--
Infinity
------------------------------------------------------------------------
Infinity's Profile: http://www.excelforum.com/member.php...o&userid=32725
View this thread: http://www.excelforum.com/showthread...hreadid=527970

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
Autorun a macro on change of cell value (having formula) Ahuja Excel Worksheet Functions 0 December 7th 06 04:47 AM
How do get a macro to autorun when i change a cell in the spreadsheet? Infinity Excel Programming 5 March 28th 06 12:14 AM
Excel Macro Issue Trying to autorun Macro Upon Opening Worksheet wyndman Excel Programming 2 May 25th 04 06:59 PM
Autorun Macro RK[_3_] Excel Programming 2 February 26th 04 12:15 PM
Autorun a macro No Name Excel Programming 2 November 21st 03 09:26 PM


All times are GMT +1. The time now is 09:04 PM.

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"