VBA Worksheet Change Event - Run A Macro When A Cell Changes
Có thể bạn quan tâm
Return to VBA Code Examples
Written by
Editorial Team
Reviewed by
Steve Rynearson
Last updated on January 10, 2022Worksheet_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.
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.
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$1" Then MsgBox "This Code Runs When Cell A1 Changes!" End If End SubYou 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!
Learn More!
VBA Code Examples Add-in
Easily access all of the code examples found on our site.
Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.
(No installation required!)
Free Download
Return to VBA Code Examples
AutoMacro: VBA Add-in with Hundreds of Ready-To-Use VBA Code Examples & much more!
Learn MoreTừ khóa » Sự Kiện Worksheet_change
-
Các Sự Kiện Khi Thao Tác Với Worksheet Trong VBA
-
Worksheet.Change Event (Excel) | Microsoft Docs
-
Khai Thác Sự Kiện Worksheet_Change VBA Excel để Cập Nhật Dữ ...
-
Xin Giúp đỡ Về Sự Kiện Worksheet_Change | Page 2
-
Event Trong VBA - Viblo
-
Tự động Cập Nhật Báo Cáo Khi Thay đổi Thời Gian Bằng VBA
-
Worksheet Change Event - Excel Dashboards VBA
-
Sự Kiện Excel Worksheet_Change Không Hoạt động - HelpEx
-
Nhiều Sự Kiện Worksheet_Change Trong Mã Vba - HelpEx
-
Worksheet Change Event: Run Excel Macros When A Cell Changes ...
-
Events (sự Kiện) Trong VBA Excel - Tài Liệu Text - 123doc
-
Có Thể Giải Thick Cho E Thêm Về Bẫy Lỗi Với Sự Kiện Worksheet_change
-
Worksheet Change Event, Excel VBA - ExcelAnytime