How to Improve Excel VBA Copy-Paste Macros and Stop Screen Flicker
Question details
The user needs to optimize a VBA macro for transferring data between workbooks, specifically to handle merged cells better, reduce repeated workbook switching, and eliminate screen flickering.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Optimizing an existing VBA macro that transfers data between workbooks, particularly when dealing with merged cells and large datasets.
- Observed behavior
- The current macro is inefficient, requires frequent workbook switching, struggles with merged cell paste areas, and causes the screen to flicker during execution.
Before editing your VBA code, ensure the Developer tab is enabled in your ribbon to access the Visual Basic Editor, and save a backup copy of your macro-enabled workbook.
Optimize VBA Code to Stop Screen Flicker and Improve Efficiency
Modify your VBA script to disable screen updating and replace inefficient copy-paste methods with direct value assignments.
Screen flickering occurs because Excel visually updates the application interface every time your macro switches workbooks or selects a new range. Disabling screen updating dramatically improves execution speed and provides a cleaner user experience.
Additionally, relying on '.Select' and '.Copy' slows down operations. Direct value assignment is much faster and avoids clipboard-related runtime errors, especially when transferring data into merged cells.
At the very beginning of your VBA macro (right after the `Sub` declaration), insert `Application.ScreenUpdating = False` to prevent the spreadsheet from refreshing the screen while the code runs.
Instead of selecting, copying, and pasting, assign values directly. For example, replace `Range("A1").Copy` and `Range("B1").PasteSpecial` with `Workbook2.Sheets("Sheet1").Range("B1").Value = Workbook1.Sheets("Sheet1").Range("A1").Value`.
When pasting data into merged cells, refer directly to the top-left cell of the merged range rather than selecting the entire merged area to prevent dimension mismatch errors.
At the end of your macro, right before the `End Sub` statement, ensure you turn screen updating back on by adding `Application.ScreenUpdating = True`.

Optimize Macros Easily with WPS Spreadsheet
WPS Office offers robust support for VBA and macros in its advanced versions, allowing you to edit, optimize, and execute scripts without the heavy resource usage that often causes screen flickering.
- 1. Open your macro-enabled workbook: Launch WPS Spreadsheet and open your .xlsm file containing the macros you want to optimize.
- 2. Access the Developer Tools: Navigate to the 'Tools' tab on the ribbon and click on 'Developer' to access the macro and code options.
- 3. Open the Visual Basic Editor: Click on 'Visual Basic Editor' to view your code. Apply the `Application.ScreenUpdating = False` optimization here.
- 4. Save and Run: Save your optimized script and run the macro directly from the WPS Spreadsheet interface for smooth, flicker-free execution.

Frequently Asked Questions
Why does my screen flicker when running an Excel VBA macro?
Screen flickering happens because Excel attempts to refresh the visual display every time your code selects a cell, switches between worksheets, or opens a new workbook. Disabling screen updating during execution prevents this visual refresh and speeds up the macro.
How do I fix the runtime error when pasting into merged cells using VBA?
Pasting copied data into merged cells often causes errors if the copied range size does not perfectly match the merged area. To fix this, use direct value assignment targeting only the top-left cell of the merged range instead of using standard '.Paste' or '.PasteSpecial' commands.
What is the difference between Application.ScreenUpdating and Application.Calculation in VBA?
Application.ScreenUpdating pauses visual changes on your monitor, stopping flickers. Application.Calculation pauses automatic formula recalculations in the background while the macro runs. Setting both to false/manual before running complex macros significantly speeds up execution time.
Do I need to turn Application.ScreenUpdating back on manually?
Yes. While some newer versions of spreadsheet software may automatically reset it after the macro finishes, it is a standard coding best practice to explicitly write `Application.ScreenUpdating = True` right before your `End Sub` statement to ensure the user interface updates correctly.




