Transferring data between Excel worksheets with VBA involves writing a macro that reads values from a source sheet and writes them to a destination sheet, either as a one-time run or automatically when something changes. Here's a practical rundown of the common approaches.
Basic manual-trigger macro
This copies a range dynamically (based on the last used row) and pastes it into the next empty row on the destination sheet, avoiding overwritten data.
Copying only specific cells or with conditions
Instead of .Copy, loop through rows and use an If statement to filter which rows qualify (e.g., only rows where a status column equals "Complete"), assigning values cell-by-cell with wsDest.Cells(r, c).Value = wsSource.Cells(r, c).Value. This avoids clipboard issues and formatting problems.
Making it automatic
To trigger the transfer without manually running the macro:
- Worksheet_Change event: Place code in the source sheet's code module using
Private Sub Worksheet_Change(ByVal Target As Range)so it fires whenever a cell is edited. - Workbook_Open event: Runs the transfer every time the file opens.
- Application.OnTime: Schedules the macro to run at set intervals.
Tips
- Use
.Valuetransfers instead of.Copy/.Pastewhen you don't need formatting, since it's faster and avoids clipboard errors. - Turn off screen flicker with
Application.ScreenUpdating = Falseat the start and re-enable it after. - Always fully qualify sheet references (
ThisWorkbook.Sheets("Name")) to avoid ambiguity when multiple workbooks are open. - Test on a copy of your file first, since macros can overwrite data irreversibly.
Access the VBA editor via Alt+F11, insert a module (Insert > Module) for standalone macros, or double-click a sheet name in the Project Explorer to add sheet-specific event code.