by Allen Wyatt
(last updated August 22, 2020)
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.
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 Office 365.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
There are many different ways you may need to enter data in a worksheet. For instance, you might want to enter data in ...Discover More
If you lose your place on the screen quite often, you might find it helpful to have not just a single cell highlighted, ...Discover More
Do you need to change whether a particular reference in a formula uses a relative or absolute reference? If so, you may ...Discover More
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.