Execute Macro On Cell Change

This macro must be embedded in the individual worksheet where it is intended to be used. There are two places to create excel VBA code. One is in modules which are viewable in the VBA project window and the other is in  the individual worksheets also viewable in the VBA project window or accessible by right clicking on the tab and selecting ‘View Code’.

This code will execute a macro based on a change in the value of cell C1. It then uses if then functionality to determine which macro to execute. A good way to make sure the cell only contains the values you want, is to use Data Validation to restrict the cell values.

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address(False, False) = “C1” Then _ ‘this defines the target cell

If Range(“C1”).Value = 1 Then Application.Run “macro_1” ‘if the cell is equal to 1 then execute macro_1.

If Range(“C1”).Value = 2 Then Application.Run “macro_2” ‘if the cell is equal to 2 then execute macro_2.

If Range(“C1”).Value = 3 Then Application.Run “macro_3” ‘if the cell is equal to 3 then execute macro_3.

End If

End Sub

Note that it is not the entering of the numbers that execute the macro, but the fact that the target cell’s value is changing.