Article ID: 166347 - Last Review: October 11, 2006 - Revision: 2.2 XL97: Using the SheetChange Event in Microsoft Excel 97This article was previously published under Q166347 On This PageSUMMARY
In Microsoft Excel, you can use the SheetChange event in Microsoft Visual Basic for Applications to automatically run a macro whenever you change the contents of any worksheet in the workbook. This article explains how to use the SheetChange event and the SheetChange subroutine.
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. How to Access the SheetChange Subroutine in the Visual Basic EditorEach workbook has a single SheetChange event. To view or edit the subroutine that uses the SheetChange event:
NOTE: The first line of the subroutine (Private Sub... Excel.Range) should be entered on a single line without an underscore (_) character. What Are "Sh" and "Target"?The SheetChange subroutine accepts two arguments. By default, these arguments are Sh and Target.
Compile error: Event procedure does not match description of event having the same name Using the SheetChange SubroutineThe SheetChange subroutine works like any other Visual Basic for Applications subroutine in Microsoft Excel. You can use the Sh and Target arguments to determine the worksheet and range of cells that changed, or to determine the value of the changed cells. You can use these values to perform other actions.For example, the following subroutine opens a workbook when you type the name into a cell in a worksheet in the active workbook: This example subroutine only accepts values that are less than or equal to 100: The following example subroutine runs another macro if you type a value in cell A1 of Sheet1: | Article Translations
|

Back to the top
