Table of Contents
VBA, or Visual Basic for Applications, is a programming language used in Excel to automate tasks and perform complex operations. One useful feature of VBA is the ability to run a macro when the value in a cell changes. This means that the macro will automatically execute when the value in the specified cell is modified. This can be achieved by using the “Worksheet_Change” event in VBA, which allows the user to specify the cell or range of cells to monitor for changes. By utilizing this feature, users can save time and improve efficiency by automating repetitive tasks that are triggered by specific changes in cell values. Overall, using VBA to run a macro when the value in a cell changes can greatly enhance the functionality and productivity of using Excel.
VBA: Run Macro When Cell Value Changes
You can use the following syntax in VBA to run a macro when a specific cell value changes:
Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" ThenCall MultiplyMacro
End IfEnd Sub
This particular example will cause the macro called MultiplyMacro to run when the value in cell A1 changes.
The following example shows how to use this syntax in practice.
Example: Run Macro When Cell Value Changes Using VBA
Suppose we create the following macro called MultiplyMacro that multiplies the values in cells A1 and B1 and displays the results in cell C1:
Sub MultiplyMacro()
Range("C1") = Range("A1") * Range("B1")
End SubFor example, suppose we have the value 12 in cell A1 and the value 3 in cell B1.
If we run this macro, we’ll receive the following output:

Now suppose that we would like to automatically run this macro whenever the value in cell A1 changes.
To do so, we can right click on the sheet name and then click View Code:

In the code editing window that appears, we can paste the following code:
Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" ThenCall MultiplyMacro
End IfEnd SubThe following screenshot shows how to do so in practice:

Now, each time we change the value in cell A1 the macro called MultiplyMacro will automatically run and perform multiplication using the new value in cell A1.
For example, suppose we change the value in cell A1 to 10. As soon as we change the value and press Enter, the macro will run:

The macro multiplies 10 by 3 and displays the result in cell C2.
Note: If you’d like to run the macro when any cell in a specific range changes, you can use the following syntax instead:
Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:B1")) Is Nothing ThenCall MultiplyMacro
End IfEnd SubThis will cause the macro called MultiplyMacro to run if any cell in the range A1:B1 changes.
Cite this article
stats writer (2024). How can I use VBA to run a macro when the value in a cell changes?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-run-a-macro-when-the-value-in-a-cell-changes/
stats writer. "How can I use VBA to run a macro when the value in a cell changes?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-run-a-macro-when-the-value-in-a-cell-changes/.
stats writer. "How can I use VBA to run a macro when the value in a cell changes?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-run-a-macro-when-the-value-in-a-cell-changes/.
stats writer (2024) 'How can I use VBA to run a macro when the value in a cell changes?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-run-a-macro-when-the-value-in-a-cell-changes/.
[1] stats writer, "How can I use VBA to run a macro when the value in a cell changes?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use VBA to run a macro when the value in a cell changes?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
