0
Thanks

A few words of thanks would be greatly appreciated.

Excel - Run Macro on Cell Change




Issue


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.
  • Is there any way to use a formula to get this accomplished? If not what is the macro code I will need.

Solution


Try to use this macro and adapt it if you need :

Private Sub Worksheet_Change(ByVal Target As Range)  
    If [A3] = 1 Then  
    Call Macro1  
    End If  
      
    If [A3] = 2 Then  
    Call Macro2  
    End If  
      
    If [A3] = 3 Then  
    Call Macro3  
    End If  
      
    If [A3] = 4 Then  
    Call Macro4  
    End If  
      
    If [A3] = 5 Then  
    Call Macro5  
    End If  
      
    If [A3] = 6 Then  
    Call Macro6  
    End If  
      
    If [A3] = 7 Then  
    Call Macro7  
    End If  
      
    If [A3] = 8 Then  
    Call Macro8  
    End If  
      
End Sub

Note that


Thanks to venkat1926 for this tip on the forum.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Excel - Run Macro on Cell Change », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!