Skip to content

VBA Worksheet Change Event – Run a Macro When a Cell Changes

Associated Files Download Links


Worksheet_Change Event

You may want to run a macro when a cell changes. A popular use of this ability is to have custom code validate a cell after a change is made. It’s easy to do this by using the worksheet objects change event.

In the Visual Basic Editor you must first double click the sheet name where the cell changes that activates the macro. This opens the code window for that sheet object. In this case I wanted to run a macro when a cell in Sheet1 changes.

worksheet change event

After opening the code window for the Worksheet you place your code in the Worksheet_Change event. The following example will display a message box if the contents of cell A1 change. First the subroutine fires if any cell changes, then the use of an IF..Then statement will run the code only if cell A1 was the cell that changed based on the If…Then.

You can place your code directly in the Worksheet_Change subroutine or call another macro from there.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

Learn More!


<<Return to VBA Examples

Did you find this VBA tutorial useful? Then share it with your friends and colleagues:

You may also like some of this related content...

The following routine will sort the sheets in a workbook alphabetically. The flag “Sort_Mode_Descending” can
Unhide All Worksheets in Workbook The following is a macro to unhide all worksheets in
This tutorial will discuss how to add / insert worksheets using VBA. Add Sheet This
Application.Sheets.Count - Count Worksheets If you ever need to count the number of sheets in
ActiveWindow.Zoom You can use VBA to change the Zoom of a worksheet. Here's code to
Advertisements
Automate Excel
Left Menu Icon