How to Automatically Transfer Excel Data to Another Sheet When a Value Is Entered
Question details
The user wants to automatically copy specific row data, including date, time, and amount, from one worksheet to another when a particular code is entered, and sort the transferred records chronologically.
- Product
- Excel
- Device & OS
- not provided
- Scenario
- Setting up a worksheet where entering a specific trigger code automatically sends the corresponding row's data to a log or summary sheet and keeps it organized by date.
- Observed behavior
- Currently, data must be transferred and sorted manually; the goal is to implement a macro or VBA script to automate the entire process based on cell value changes.
Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled macros in your security settings to allow the automated scripts to run.
Use Worksheet_Change VBA Event to Automate Data Transfer
By utilizing the Worksheet_Change event in VBA, you can trigger a macro to copy data to a destination sheet automatically as soon as a specific value is typed into a designated column.
This method relies on a built-in event handler that constantly monitors a specific worksheet for changes. When it detects that a value matching your specific code has been entered into the target column, it executes the copy and paste commands.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
In the Project Explorer pane on the left, double-click the source sheet (e.g., Sheet1) where you will be entering the trigger code.
From the left dropdown at the top of the code window, select 'Worksheet', and from the right dropdown, select 'Change'. This creates the Private Sub Worksheet_Change(ByVal Target As Range) framework.
Insert VBA code using 'If Not Intersect(Target, Range("A:A")) Is Nothing' to check if the entry occurred in your target column. Then, add logic to copy the active row's data and paste it into the next available empty row on your destination sheet.
At the end of your script, include a sorting command referencing your destination sheet's date column (e.g., Range.Sort Key1:=Range("B2"), Order1:=xlAscending) to keep the transferred records in chronological order.
Automate Data Transfers Easily with WPS Office
WPS Spreadsheet offers powerful scripting capabilities, including VBA and JS Macros, enabling you to seamlessly automate worksheet data transfers and sorting without manual effort.
- 1. Install WPS Office: Download and install WPS Office, then open your existing workbook in WPS Spreadsheet.
- 2. Access the Developer Tools: Navigate to the 'Tools' or 'Developer' tab on the top ribbon menu to access macro features.
- 3. Write or Paste Your Script: Click on 'Macros' or the 'Macro Editor' to insert your VBA or JS Macro code for automating the data transfer and sorting based on cell values.
- 4. Save as Macro-Enabled: Save your file in a macro-enabled format to ensure your automated triggers remain active every time you open the document.

Frequently Asked Questions
Why isn't my VBA code triggering when I enter a value?
This usually happens if Macros are disabled in your Trust Center settings, or if 'Application.EnableEvents' was accidentally set to False during a previous macro execution. Ensure macros are enabled and try running a quick script to set EnableEvents back to True.
Can I use formulas instead of VBA to transfer data automatically?
Formulas like FILTER, VLOOKUP, or INDEX/MATCH can display data dynamically on another sheet based on a criteria, but they do not physically copy or permanently store the static values. For permanent transfer and sorting of historical entries, a macro or VBA is required.
How do I ensure the macro finds the next empty row on the destination sheet?
In your VBA script, you can define the next empty row by counting the rows from the bottom up. A common method is using logic like: 'NextRow = Sheets("Destination").Cells(Rows.Count, 1).End(xlUp).Row + 1'.




