Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to run macro when cell value changes in Excel?

Normally, in Excel, we can press F5 key or Run button to execute the VBA code. But, have you ever tried to run the specific macro code when a cell value changes? This article, I will introduce some quick tricks to deal with this job in Excel.

Run or call macro when a specific cell value changes with VBA code

Run or call macro when any cell value changes in a range with VBA code


Remove all macros from multiple workbooks:

Kutools for Excel's Batch Remove All Macros utility can help you to remove all macros from multiple workbooks as you need. Download and free trial Kutools for Excel now!

doc run macro if cell changes 3

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


arrow blue right bubble Run or call macro when a specific cell value changes with VBA code


To run a macro code by changing a cell value, the following VBA code can do you a favor, please do as this:

1. Right click the sheet tab that you want to execute the macro if cell value changes, and then choose View Code from the context menu, and in the opened Microsoft Visual Basic for applications window, copy and paste the following code into the blank Module:

VBA code: Run macro when cell value changes:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        Call Mymacro
    End If
End Sub

doc run macro if cell changes 1

Note: In the above code, A1 is the specific cell that you want to run the code based on, Mymacro is the macro name which you want to run. Please change them to your need.

2. And then save and close the code window, now, when you enter or change value in cell A1, the specific code will be triggered at once.


arrow blue right bubble Run or call macro when any cell value changes in a range with VBA code

If you want to run or trigger a macro when anyone cell value changes in a range of cell, the following code may help you.

1. Right click the sheet tab that you want to execute the macro if cell value changes, and then choose View Code from the context menu, and in the opened Microsoft Visual Basic for applications window, copy and paste the following code into the blank Module:

VBA code: Run macro when any cell value changes in a range:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:B100")) Is Nothing Then
Call Mymacro
End If
End Sub

doc run macro if cell changes 2

Note: In the above code, A1:B100 is the specific cells that you want to run the code based on, Mymacro is the macro name which you want to run. Please change them to your need.

2. And then save and close the code window, now, when you enter or change value in anyone cell of A1:B100, the specific code will be executed at once.


Related articles:

How to run macro automatically before printing in Excel?

How to run macro based on cell value in Excel?

How to run macro based on value selected from drop down list in Excel?

How to run macro by clicking hyperlinks in Excel?

How to run macro when sheet is selected from a workbook?


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    roberto · 6 months ago
    Hola buenas tardes
    quisiera saber el codigo para que se active una macro cuando cambia el valor de una celda de una columna, pero este valor cambia por formula,sin que el usuario introduzca ningun valor.
  • To post as a guest, your comment is unpublished.
    DrCartwright · 8 months ago
    The macro that you are calling where do you have this located? I have mine in the Modules folder but when I put any value in any cell of the worksheet I get a Compile error saying:
    Expected variable or procedure, not module.

    Please help.
    • To post as a guest, your comment is unpublished.
      skyyang · 7 months ago
      Hi, DrCartwright,
      Sorry for replying to you so late.
      Yes, as you said, the macro code should be located into the Module, and you need to change the code name to your own name as following screenshot shown:
  • To post as a guest, your comment is unpublished.
    Kevin · 9 months ago
    Hey, useful code. I was thinking if it was possible to insert a ring around the cells that are changed as they are changed? And reset the circles every Monday ?
    • To post as a guest, your comment is unpublished.
      skyyang · 9 months ago
      Hello, Kevin,
      Here is no idea for solving your problem, if you have any good solution, please comment here.
  • To post as a guest, your comment is unpublished.
    Tom · 1 years ago
    Worked great for me! My dilemma is that I want it to be a relative reference macro and there is a difference between hitting enter to save the entry and delete to clear the cell.
  • To post as a guest, your comment is unpublished.
    Andrew Cothliff · 1 years ago
    This worked first time for me using data validation list which displays text based on the list selection.