VBA & Macro Problems

How to Use a VBA Macro to Copy Matching Values to Another Worksheet in Excel

Olivia MillerOlivia Miller Nov 3, 2026 870 views

Question details

The user needs a VBA macro to search for a specific value ('Y') in a column (Column C) and copy the corresponding data from another column (Column F) to the next available empty row on a different worksheet.

How to Use a VBA Macro to Copy Matching Values to Another Worksheet
Product
Spreadsheet
Device & OS
not provided
Scenario
Automating data extraction and transfer between worksheets based on a specific condition.
Observed behavior
Needs to identify matching rows and dynamically place the target values into the next available row on a destination sheet without triggering paste-area size mismatches.
Before you start

Ensure you have saved your workbook as a Macro-Enabled Workbook (.xlsm) and that the Developer tab is enabled to access the VBA editor.

Solution 1Recommended

Create a VBA Macro to Copy Specific Column Values Based on Criteria

Use this method to loop through your data, check for the condition ('Y' in Column C), and copy only the specific corresponding value (Column F) to the next empty row.

This approach uses variables to track both the source sheet and destination sheet. It dynamically calculates the last used row on the destination sheet to ensure data is appended without overwriting existing records.

1
Open the VBA Editor

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

2
Insert a New Module

Click 'Insert' from the top menu and select 'Module' to create a blank script window for your code.

3
Write the Macro Code

Write a script that loops through the source sheet. Use an 'If' statement to check if cells in Column C equal 'Y'. If true, copy the offset cell in Column F to the destination sheet using 'Cells(Rows.Count, 1).End(xlUp).Row + 1' to find the next empty row.

4
Run the Macro

Press 'F5' or click the 'Run' button. The matching values from Column F will be successfully copied to Column A of your destination worksheet.

Create a VBA Macro to Copy Specific Column Values Based on Criteria
Worksheet Names: Make sure the names of the source and destination worksheets in your VBA code match the actual tab names in your file exactly.
Recommended Spreadsheet Software

Use WPS Spreadsheet to Easily Run VBA Macros for Data Filtering

WPS Office offers robust support for VBA macros, allowing you to seamlessly run your scripts to copy and paste matching values across worksheets. It provides an intuitive interface and reliable compatibility with standard Excel VBA syntax.

  1. 1. Download and Install: Download WPS Office and launch the WPS Spreadsheet application.
  2. 2. Open your Macro Workbook: Open your .xlsm file containing the source data and VBA scripts.
  3. 3. Enable the Developer Tab: Navigate to the settings to display the Developer tab, then click 'Macros' to manage your scripts.
  4. 4. Run the Script: Select your macro and click 'Run' to instantly filter and copy your matching rows or values.
Fully compatible with Microsoft Excel formats (.xlsx, .xls, .xlsm).Supports standard VBA syntax and seamless macro execution.Free and lightweight alternative for automating daily spreadsheet tasks.Familiar user interface with a built-in Developer tab.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a paste-area size mismatch error when copying entire rows?

This error occurs if you try to paste an entire row starting in any column other than Column A (e.g., Column B). An entire row contains the maximum number of columns allowed in a sheet, so shifting the paste area to the right exceeds the spreadsheet's maximum column capacity.

How do I find the next available empty row using VBA?

You can find the next empty row dynamically in VBA using a code snippet like `NextRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1`. This looks up from the very bottom of Column A to find the last used row and adds 1.

Can I copy values based on multiple conditions instead of just one?

Yes, you can modify the `If` statement in your VBA loop to include multiple criteria using logical operators like `And` or `Or` (for example, `If cell.Value = "Y" And cell.Offset(0, 1).Value = "Yes" Then`).