How to Use VBA to Synchronize Two Excel Cells and Data Validation
Question details
The user needs to synchronize two specific cells using VBA so that changing one automatically updates the other's formula and data validation rules.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating an interactive spreadsheet where updating either a contact or customer name cell dynamically updates the associated lookup formula and dropdown validation list in the opposite cell.
- Observed behavior
- The goal is to have the cells bidirectionally synchronized using a Worksheet_Change event without triggering an infinite recursive loop.
Before adding the VBA code, verify the exact cell references you wish to monitor (e.g., D13 and D14) and note down the exact names of your defined data validation lists.
Use the Worksheet_Change Event to Synchronize Cells and Validation
Apply a VBA macro on the specific worksheet to detect changes in either target cell, temporarily disable events to prevent recursive loops, and update the corresponding cell's formula and validation.
When dealing with bidirectional cell updates in VBA, modifying one cell triggers an event that modifies the second cell, which in turn triggers another event. To prevent this infinite loop, we use the Application.EnableEvents property during the update process.
Right-click on the worksheet tab at the bottom of your screen where you want the synchronization to happen and select 'View Code' to open the VBA editor.
In the code window, set up a 'Private Sub Worksheet_Change(ByVal Target As Range)' event. Use an 'If Not Intersect(Target, Range("D13:D14")) Is Nothing' condition to check if the changed cell is one of your target cells.
Add 'Application.EnableEvents = False' at the beginning of your logic. This ensures that the macro's modifications to the worksheet do not trigger another change event.
Write the logic for each cell: If D13 changes, assign the appropriate lookup formula to D14 and set its Validation to your customer list. If D14 changes, set the reverse formula in D13 and its Validation to the corresponding name list.
At the very end of your code block, add 'Application.EnableEvents = True' to restore normal VBA event monitoring for future changes.

Execute Macros and VBA Scripts Seamlessly in WPS Spreadsheet
WPS Office provides robust support for VBA and macros, allowing you to automate repetitive tasks and synchronize cells using the exact same Worksheet_Change events as Microsoft Excel.
- 1. Open your Workbook in WPS Spreadsheet: Launch WPS Office and open your macro-enabled file (.xlsm) containing the data validation lists.
- 2. Enable Developer Tools: Go to the 'Developer' tab in the top ribbon to access macro features. If prompted, enable macros for the document.
- 3. Access the VBA Editor: Click on 'Visual Basic' or press 'Alt + F11' to open the built-in VBA editor in WPS.
- 4. Implement the Change Event: Double-click your worksheet in the Project Explorer on the left, and paste your synchronization script, ensuring 'Application.EnableEvents' is used correctly.

Frequently Asked Questions
Why does my Excel freeze when I try to synchronize two cells with VBA?
This usually happens due to an infinite recursive loop. When Cell A updates Cell B via VBA, the change in Cell B triggers the event again to update Cell A, looping forever. To fix this, always use 'Application.EnableEvents = False' before updating the cell, and set it back to 'True' afterward.
Can I dynamically apply data validation rules using VBA?
Yes. You can use the 'Range.Validation.Add' method or modify existing validation formulas in VBA to dynamically update dropdown lists based on conditions or inputs in other cells.
How do I ensure the VBA macro only runs for specific cells?
Use the 'Intersect' function within your Worksheet_Change event. For example, 'If Not Intersect(Target, Range("D13:D14")) Is Nothing Then' ensures the macro logic only triggers when a user edits cells D13 or D14.




