Copying Rows between Worksheets Based on a Text Value

Written by Allen Wyatt (last updated August 22, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


5

Marian wonders if there is a way to copy an entire row from one worksheet to another worksheet based on the occurrence of a specific text value ("yes") in column E of the row. Vlookup doesn't seem to work for this type of evaluation.

If you only need to do this type of task sporadically, then you can simply use the filtering capabilities of Excel. Turn on filter and filter your data so it only shows rows that have "yes" in column E. Copy the visible rows and paste them into whatever worksheet you want.

If you have to do the task more often, you could create a macro to make the copying a snap. The following macro examines the first 1,000 rows of Sheet1 and copies to Sheet2 any rows containing "yes" in column E.

Sub CopyYes()
    Dim c As Range
    Dim j As Integer
    Dim Source As Worksheet
    Dim Target As Worksheet

    ' Change worksheet designations as needed
    Set Source = ActiveWorkbook.Worksheets("Sheet1")
    Set Target = ActiveWorkbook.Worksheets("Sheet2")

    J = 1     ' Start copying to row 1 in target sheet
    For Each c In Source.Range("E1:E1000")   ' Do 1000 rows
        If c = "yes" Then
           Source.Rows(c.Row).Copy Target.Rows(j)
           j = j + 1
        End If
    Next c
End Sub

Note that the macro will overwrite any information already on Sheet2. It also is not "dynamic," meaning that if the values in column E change and you want the rows in Sheet2 to reflect those changes, then the macro won't help.

Additional information about automatically copying information from one worksheet to another can be found on this website:

https://www.mrexcel.com/forum/excel-questions/602635-
automatically-move-entire-rows-one-worksheet-into-
another-worksheet-same-workbook.html

Even though the URL is shown on three lines here, it is all a single URL. You'll want to make sure you get it all into your browser.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13399) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Changing the Type of Page Numbers Used in Headers or Footers

Like to have your page numbers displayed using different types of numbers? Here's how you can choose from the several ...

Discover More

Indenting Cell Contents

Excel allows you to apply several types of alignments to cells. One type of alignment allows you to indent cell contents ...

Discover More

Excel Serious Sorting

Sorting data means that you organize it in whatever order you desire. Excel's sorting feature can be used in a variety of ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Stopping Feet and Inches from Converting to Dates

When pasting information into a worksheet, Excel tries to helpfully convert that information. This can cause undesired ...

Discover More

Viewing the Contents of a Very Wide Cell on Demand

Each cell in a worksheet can hold quite a bit of information. If you want to see the information in the cell without the ...

Discover More

Deleting All Rows Except for the End of Month

If you use a worksheet to track day-to-day data, you might want to delete all of the data except the data for the last ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 5?

2021-09-16 17:22:09

Adam

Hello, is there a way to do exactly this but with a text string? Help very much appreciated


2021-05-21 12:10:33

John

This worked great for me. Anyway to add more source worksheets?


2020-11-13 17:02:40

Alan Elston

@ tania
In Allen Wyatt's macro, replace
If c = "yes" Then
with
If c = "yes" Or c="no" or c="maybe" Then

Alan Elston


2020-11-12 16:59:23

tania

What if I have multiple values to search for eg "yes" no" "maybe"


2020-08-24 12:44:16

Gregg

Great tip! The link to Mr. Excel's forum doesn't seem to be working. Hoping you can re-post. Thanks!


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.