You will always need to include the dollar signs in the cell reference when you use this method. $A$1 refers to cell A1 and the dollar signs are just another way to reference a cell using what's called an absolute reference.
#Excel vba on cell change example code
Just change $A$1 to whichever cell you want to check and then put the code that you want to run inside the IF statement. This is a very simple and easy-to-use template. This checks if cell A1 was the cell that was changed and, if it was, a message box appears. To do this, we use an IF statement and, in this example, Target.Address. As such, we need to make sure that the cell that we want to check is the one that the user is changing. Lets now see an example of how we can use the Address Property of the Range. In the window that opens, select Worksheet from the left drop-down menu and Change from the right drop-down menu.įor more info on creating macros, view our tutorial on installing a macro in Excel.Įxcel will actually run the code that we input here each time a cell within the worksheet is changed, regardless of which cell is changed. Excel VBA: Automatically Run Excel Macros When a Cell Changes/Enter Data. Go to the VBA Editor (Alt + F11) and double-click the name of the spreadsheet that contains the cell that will change or just right-click the worksheet tab and click View Code. This works on a specific cell and is the easiest method to use. Notes Run Macro When a Cell Changes (Method 1)
Run Macro when a Cell in a Range of Cells is Changed Run a macro in Excel when a specific cell is changed this also covers when a cell within a range of cells is changed or updated.