Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do get a macro to autorun when i change a cell in the spreadsheet?


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.

Thanks in advance.


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How do get a macro to autorun when i change a cell in the spreadsh

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
--
HTH...

Jim Thomlinson


"Infinity" wrote:


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.

Thanks in advance.


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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do get a macro to autorun when i change a cell in the spreadsheet?


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 = False
End Sub


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=526617

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do get a macro to autorun when i change a cell in the spreadsheet?


That was quick... Thanks guys. Will try it out now.:)


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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default How do get a macro to autorun when i change a cell in the spre

Mudraker had a slight oversight. The last line of mudraker's code should be:
Application.EnableEvents = True

Regards,
Greg

"Infinity" wrote:


That was quick... Thanks guys. Will try it out now.:)


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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do get a macro to autorun when i change a cell in the spreadsheet?


Greg

Thanks for picking up my mistake - silly me forgot to change setting
from False to True after copying & pasting that line of code


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=526617

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 Macro chrisnsmith Excel Worksheet Functions 5 February 4th 09 07:25 PM
Autorun a macro on change of cell value (having formula) Ahuja Excel Worksheet Functions 0 December 7th 06 04:47 AM
Excel Macro Issue Trying to autorun Macro Upon Opening Worksheet wyndman Excel Programming 2 May 25th 04 06:59 PM
autorun a macro Reab Excel Programming 1 November 28th 03 09:42 PM
Autorun macro on opening spreadsheet simonjackson79 Excel Programming 3 November 5th 03 02:22 PM


All times are GMT +1. The time now is 08:54 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"