A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Excel - Run Macro on Cell Change



 
 
Thread Tools Display Modes
  #1  
Old April 20th, 2010, 05:58 PM posted to microsoft.public.excel.misc
Malaria Man
external usenet poster
 
Posts: 1
Default Excel - Run Macro on Cell Change

I am trying to have 1 of 8 different macro's run depending on the value of a
specific cell.
If I enter 1 in cell A3, I would like macro1 to run. If I change cell A3 to
2, I would like macro2 to run and so on all the way up to entering 8 and
getting macro8 to run. I am unable to find any good examples of how to do
this. I realize I will probably have to use Worksheet Event to do this but
what is the macro code I will need.
  #2  
Old April 20th, 2010, 06:06 PM posted to microsoft.public.excel.misc
Jim Thomlinson
external usenet poster
 
Posts: 2,641
Default Excel - Run Macro on Cell Change

Right click the sheet tab and select veiw code. Paste the following:

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address = "$A$3" Then
Select Case .Value
Case "A" 'Change A
Call macro1
Case "B" 'Change B
Call macro2
End Select

End If
End With
End Sub

Chang ethe A and B to the values that you want to trigger the macros. Add as
many different cases as you need.
--
HTH...

Jim Thomlinson


"Malaria Man" wrote:

I am trying to have 1 of 8 different macro's run depending on the value of a
specific cell.
If I enter 1 in cell A3, I would like macro1 to run. If I change cell A3 to
2, I would like macro2 to run and so on all the way up to entering 8 and
getting macro8 to run. I am unable to find any good examples of how to do
this. I realize I will probably have to use Worksheet Event to do this but
what is the macro code I will need.

  #3  
Old April 20th, 2010, 06:10 PM posted to microsoft.public.excel.misc
Paul C
external usenet poster
 
Posts: 202
Default Excel - Run Macro on Cell Change

Create a Worksheet Change macro and check the target position and value like
this.

If any cell but A3 is changed nothing get executed


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Row=3 and Target.Column=1 then
Select Case target.value
Case 1
Call macro1
Case 2
Call macro2
etc...
End Select
End If

End Sub


--
If this helps, please remember to click yes.


"Malaria Man" wrote:

I am trying to have 1 of 8 different macro's run depending on the value of a
specific cell.
If I enter 1 in cell A3, I would like macro1 to run. If I change cell A3 to
2, I would like macro2 to run and so on all the way up to entering 8 and
getting macro8 to run. I am unable to find any good examples of how to do
this. I realize I will probably have to use Worksheet Event to do this but
what is the macro code I will need.

  #4  
Old April 20th, 2010, 06:10 PM posted to microsoft.public.excel.misc
Don Guillett[_2_]
external usenet poster
 
Posts: 607
Default Excel - Run Macro on Cell Change

Ease of design depends on the actual names of the macros. Assuming they are
NOT really macro1 , macro2, etc then I suggest a select case macro something
like

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Or _
Target.Address Range("a3").Address Then Exit Sub
Select Case Target
Case Is = 1: Call macro1
Case Is = 2: Call macro2
Case Else: MsgBox "no such"
End Select
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Malaria Man" Malaria
wrote in message
...
I am trying to have 1 of 8 different macro's run depending on the value of
a
specific cell.
If I enter 1 in cell A3, I would like macro1 to run. If I change cell A3
to
2, I would like macro2 to run and so on all the way up to entering 8 and
getting macro8 to run. I am unable to find any good examples of how to do
this. I realize I will probably have to use Worksheet Event to do this but
what is the macro code I will need.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


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