VBA & Macro Problems

How to Copy Data to the Next Sheet Using a VBA Macro

Maira MehtabMaira Mehtab Nov 10, 2026 869 views

Question details

The user needs a VBA macro to conditionally copy a specific range of cells from the currently active worksheet to the next worksheet without using hard-coded sheet names.

How to Copy Data from the Active Sheet to the Next Sheet Using VBA
Product
Spreadsheet
Device & OS
not provided
Scenario
Automating data transfer between sequential worksheets based on a specific condition, such as copying cells in column B only when the corresponding cell in column A contains a specific value.
Observed behavior
The user wants a single, unified macro procedure to handle the conditional copying without triggering method errors or needing to run multiple separate macros.
Before you start

Ensure that your workbook contains at least one worksheet after the active sheet to prevent out-of-bounds errors, and save your file as a Macro-Enabled Workbook (.xlsm) before running the code.

Solution 1Recommended

Write a VBA Macro to Conditionally Copy Data to the Next Sheet

Use a VBA For loop to check conditions and the ActiveSheet.Next property to reference the destination sheet dynamically.

By using the ActiveSheet.Next property, you avoid hard-coding worksheet names, making the macro flexible regardless of what the sheets are called. The code loops through the specified range, checks the condition in column A, and copies the value to the corresponding cell in the next sheet.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor in your spreadsheet software.

2
Insert a New Module

Click on 'Insert' in the top menu bar and select 'Module' to create a new blank module for your macro code.

3
Enter the VBA Code

Create a Sub procedure. Use a For loop (e.g., For i = 11 To 21). Inside the loop, use an If statement to check the condition: If ActiveSheet.Cells(i, 1).Value = "T" Then. If true, transfer the data using: ActiveSheet.Next.Cells(i, 2).Value = ActiveSheet.Cells(i, 2).Value.

4
Run the Macro

Close the VBA editor to return to your active worksheet. Press Alt + F8, select your newly created macro from the list, and click 'Run'.

Write a VBA Macro to Conditionally Copy Data to the Next Sheet
Handling Multiple Ranges: If you need to expand the range or add more cells, modify the loop boundaries (e.g., changing 11 To 21 to your desired row numbers) rather than creating separate macros for each range.
Advanced Spreadsheet Automation

Automate Your Workflows with WPS Spreadsheet

WPS Office provides robust support for VBA and macros, allowing you to automate repetitive tasks like conditional data copying across sheets seamlessly.

  1. 1. Download and Install: Download WPS Office from the official website and install it on your computer.
  2. 2. Enable VBA Support: Open WPS Spreadsheet. Navigate to the Developer tab to ensure the VBA module is enabled and ready for use.
  3. 3. Run Your Macros: Click on 'Macros' or 'Visual Basic' in the Developer tab to write and execute your VBA scripts just as you would in Excel.
Fully compatible with Microsoft Excel VBA macros and scripts.Built-in VBA editor for writing, debugging, and running custom code.Lightweight and fast performance for handling large datasets.Free to use with a familiar, tabbed user interface.
microsoft office alternative - wps office

Frequently Asked Questions

How do I reference the next worksheet in VBA without using its name?

You can use the ActiveSheet.Next property in VBA. This dynamically refers to the worksheet immediately following the currently active one, regardless of its name.

Why do I get an object error when running the macro?

This usually happens if the active sheet is the last sheet in the workbook. ActiveSheet.Next will return an error because there is no subsequent sheet to reference. Always ensure a next sheet exists before running the code.

Can I modify the VBA code to check for a different condition?

Yes. In the If statement of your VBA code (e.g., If Cells(i, 1).Value = "T"), simply replace "T" with your desired text, number, or condition.

How do I apply this macro to multiple columns instead of just column B?

You can expand the code by adding more lines inside the If statement to copy other columns (e.g., ActiveSheet.Next.Cells(i, 3).Value = ActiveSheet.Cells(i, 3).Value for column C), or by using the Range.Copy method for a broader selection.