Extracting data to another worksheet

Sparky

Board Regular
Joined
Feb 18, 2002
Messages
210
Office Version
  1. 2010
Platform
  1. Windows
I have a worksheet where Yes or No appears in column A. I require all the rows with Yes to be copied across to another worksheet in the same workbook. Hope someone can help with a piece of code or a formula.

Thanks
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi Sparky,

How about...

Code:
Sub MoveData()
    Dim r As Range, LR As Long
    With Sheets("Sheet1")
        LR = .Range("A" & Rows.Count).End(xlUp).Row
        Set r = .Range("A2").Resize(LR - 1)
        .Range("A1").AutoFilter field:=1, Criteria1:="Yes"
        With r.SpecialCells(xlCellTypeVisible).EntireRow
            .Copy Destination:=Sheets("Sheet2").Range("A2")
        End With
        .Range("A1").AutoFilter
    End With
End Sub
 
Upvote 0
Jeff

The code always seems to pick up the first row of data from sheet1 irrespective if it is YES or NO.

Two or three times a day I will update sheet1 with fresh data and occasionally delete some or all of the data as it is used. If I delete from sheet1 is there a way for it to automatically delete in sheet2. The method I am using to delete is by selecting the numbered rows, right click and select delete.

Hope you can help.
 
Upvote 0
Jeff

I have had a look at the resize property to see what its purpose is. As this (resize LR -1) is to allow for the table I have now placed header names above the data in Sheet1. This seems to have done the trick. Please correct me if I am wrong.

Thanks again
 
Upvote 0
Hi Sparky,

Yes, having headers to your data is vitally important. The idea of an autofilter is to have a header to filter on or else you are confusing Excel.

Not entirely sure what you want to do (delete) and when or why, but the updated code below will not only filter the data on sheet1 and move it to sheet2, but will also delete from sheet1 what you just moved to sheet2.

If you need something else please provide more details as to what you would like to achieve?

Code:
Sub MoveData()
    Dim r As Range, LR As Long
    With Sheets("Sheet1")
        LR = .Range("A" & Rows.Count).End(xlUp).Row
        Set r = .Range("C2").Resize(LR - 1)
        .Range("A1").AutoFilter field:=3, Criteria1:="Replace"
        With r.SpecialCells(xlCellTypeVisible).EntireRow
            .Copy Destination:=Sheets("Sheet2").Range("A5")
            [COLOR="Red"].Delete[/COLOR]        
     End With
        .Range("A1").AutoFilter
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,702
Members
452,938
Latest member
babeneker

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