Copy entire row if cell contains specific value

Phily50

New Member
Joined
Jul 8, 2013
Messages
28
Office Version
  1. 365
Platform
  1. Windows
So I have a workbook with three sheets.

Master - this contains the full data
Destroyed and Retained

Within Master there is a column (G) that has a "Y" to indicate that the file has been destroyed and an "N" to indicate that the file is retained. Currently some are blank but these will be changed as and when the documents are reviewed. There will also be further data added to the master sheet as time goes on.

The headings in all three sheets will be the same

What I am after is either a code or a formula that scans the master sheet and copies the entire row (columns A to M) into destroyed and retained dependant on column G (the Y/N). I would need this to either update dynamically or through the push of a button prior to exiting. Currently I'm manually adding them b y copy pasting and then sorting them by date, its rather laborious and repetitive!

I had a go using FILTER but couldn't work it out.

Grateful of any assistance.
 
This should make more sense.
Code:
Sub Maybe()
Application.ScreenUpdating = False
With Range("A1:M" & Cells(Rows.Count, 2).End(xlUp).Row)
  .AutoFilter 7, "Y"
    .Offset(1).Resize(.Rows.Count - 1).EntireRow.Copy
        Sheets("Destroyed").Cells(Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial
            .AutoFilter 7, "N"
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Copy
    Sheets("Retained").Cells(Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial
  .AutoFilter
End With
Application.ScreenUpdating = True
End Sub
Have not heard if sheets need to be cleared, which makes sense also and have not included sorting.
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
OK, see what you were getting at now. :)


Just wondering if you have actually tested your code though? It didn't work correctly for me.

And also wondering how that code would handle the following without continually adding the same data to the other sheet(s)


@Phily50

I had overlooked this comment previously. If you could advise which column contains the date, my formulas could be adjusted so that the data was also sorted by date (if it isn't already).
Hi Peter, the formula works but with reference to which column I need it sorted by is J

*edit* is there a way to deal with blanks? currently blank cells are showing as 0
 
Upvote 0
*edit* is there a way to deal with blanks? currently blank cells are showing as 0
Below is one way.
I have also included the sorting though I wasn't sure if the dates should be ascending or descending. If I have it the wrong sort order than change to 1 at the end of the formula to -1.
Provided where I have 1000 in the formula you have used a number big enough to include any amount of data you are likely to end up with everything should automatically update as you add/remove/edit data on the Master sheet.

Phily50.xlsm
ABCDEFGHIJKLM
1Hdr1Hdr2Hdr3Hdr4Hdr5Hdr6DestroyedHdr8Hdr9DateHdr11Hdr12Hdr13
2Data 67Data 35Data 16Data 10YData 80805-Aug-22Data 47Data 64Data 25
3Data 13Data 90Data 5Data 2NData 57616-Jul-20Data 36Data 18Data 42
4Data 16Data 71Data 38Data 52Data 8514-May-22Data 70Data 81Data 15
5Data 66Data 21Data 47Data 41NData 1518-Jan-23Data 35Data 3Data 29
6Data 76Data 25Data 81Data 76Data 36Data 90YData 3325-Jun-22Data 62Data 71Data 46
Master


Phily50.xlsm
ABCDEFGHIJKLM
1Hdr1Hdr2Hdr3Hdr4Hdr5Hdr6DestroyedHdr8Hdr9DateHdr11Hdr12Hdr13
2Data 76Data 25Data 81Data 76Data 36Data 90YData 3325-Jun-22Data 62Data 71Data 46
3Data 67Data 35Data 16Data 10YData 80805-Aug-22Data 47Data 64Data 25
4
Destroyed
Cell Formulas
RangeFormula
A2:M3A2=LET(r,Master!A2:M1000,SORT(FILTER(IF(r="","",r),Master!G2:G1000="Y",""),10,1))
Dynamic array formulas.


Phily50.xlsm
ABCDEFGHIJKLM
1Hdr1Hdr2Hdr3Hdr4Hdr5Hdr6DestroyedHdr8Hdr9DateHdr11Hdr12Hdr13
2Data 13Data 90Data 5Data 2NData 57616-Jul-20Data 36Data 18Data 42
3Data 66Data 21Data 47Data 41NData 1518-Jan-23Data 35Data 3Data 29
4
Retained
Cell Formulas
RangeFormula
A2:M3A2=LET(r,Master!A2:M1000,SORT(FILTER(IF(r="","",r),Master!G2:G1000="N",""),10,1))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top