VBA & Macro Problems

Fix Excel VBA Macro That Must Run Twice to Copy Data Correctly

Chanuka GeekiyanageChanuka Geekiyanage Nov 3, 2026 870 views

Question details

The user's Excel VBA macro fails to copy all data correctly on the first execution, requiring a second run to complete the task.

How to Fix Excel VBA Macro Requiring Multiple Runs to Copy Data Correctly
Product
Excel
Device & OS
not provided
Scenario
Running a VBA macro script to copy data rows between different workbooks.
Observed behavior
Values are missing or incorrect after the first run, but they appear correctly after running the exact same macro a second time.
Before you start

Before modifying your VBA code, review the end of your script to check the ScreenUpdating property and save a backup copy of your Excel workbooks to prevent accidental data loss during testing.

Solution 1Recommended

Correct ScreenUpdating and Qualify VBA References

Updating your VBA code to restore screen updating and explicitly stating workbooks and worksheets prevents data from pasting into the wrong active window or hiding the results.

A macro appearing to fail on the first run is almost always caused by 'Application.ScreenUpdating' being left as 'False', or by using unqualified references. Unqualified references rely on whatever sheet happens to be active, which can shift dynamically during execution.

1
Restore Screen Updating

Scroll to the very end of your macro script. If you see the line 'Application.ScreenUpdating = False', change it to 'Application.ScreenUpdating = True'. This ensures Excel refreshes the UI after the macro finishes.

2
Qualify Workbook and Worksheet References

Ensure every 'Range', 'Cells', and 'Rows' object in your copy/paste code is preceded by its specific worksheet object. For example, assign variables like 'Set wsSource = Workbooks("Source.xlsx").Sheets("Data")' and then strictly use 'wsSource.Range(...)'.

3
Correct Last-Row Detection

When determining the last row for your destination worksheet, explicitly qualify the rows count: use 'wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Row' instead of an unqualified 'Rows.Count', which might calculate based on the wrong sheet.

Correct ScreenUpdating and Qualify VBA References
Best Practice: Always declare your workbook and worksheet objects explicitly. It makes your code run faster and prevents errors caused by users clicking into different windows while the macro runs.

Edit and Run Macros Flawlessly in WPS Spreadsheet

WPS Office provides robust support for VBA macros. You can easily open, edit, and troubleshoot your macro-enabled workbooks directly within WPS Spreadsheet, ensuring a smooth scripting experience.

  1. 1. Open your Macro Workbook: Launch WPS Spreadsheet and open your .xlsm or .xls file containing the macro.
  2. 2. Access the Developer Tools: Navigate to the 'Developer' tab on the top ribbon. If it is not visible, you can easily enable it in the WPS Options menu.
  3. 3. Open the VBA Editor: Click on the 'Visual Basic' or 'Macros' icon to launch the built-in VBA editor.
  4. 4. Correct the Code: Apply the explicit worksheet references and fix your ScreenUpdating logic, then save your changes.
  5. 5. Run and Test: Execute the macro again directly from the WPS interface to ensure data copies correctly on the very first run.
Built-in developer tools and comprehensive VBA editorHigh compatibility with Microsoft Excel macros (.xlsm) and scriptsLightweight installation and incredibly fast executionFree alternative offering professional-grade data handling
microsoft office alternative - wps office

Frequently Asked Questions

Why does my macro only show results after I run it a second time?

This usually occurs when 'Application.ScreenUpdating' is left as 'False' at the end of the script. The script prevents Excel from redrawing the screen to save resources. A manual click or a second run forces the application UI to finally refresh and display the copied data.

What does an unqualified reference mean in Excel VBA?

An unqualified reference is when you use properties like 'Range' or 'Cells' without specifying which workbook or worksheet they belong to. When omitted, VBA defaults to whatever sheet is currently active. If the active sheet shifts during execution, your data is pulled from or pasted into the wrong place.

Can an incorrect last-row calculation cause a macro to skip copying data?

Yes. If your macro calculates the last row using 'Rows.Count' without specifying the target worksheet, it might pull the row count from the wrong sheet. This causes the copied data to overwrite existing rows or be placed entirely out of your viewing area, making it seem like the copy failed.