Move Data from One Sheet to another

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
828
Office Version
  1. 365
Platform
  1. Windows
Trying to Move Data from Sheet 1 to Sheet2 if Column D has Closed in it
Below code doesnt seem to move it all. is there a better easier way to do it. ALso dont necessarily need selected cells prefer rage to be just Col D and when it finds it will copy all the rows to sheet 2 and then delete the Data on Sheet1

ALso need it to paste to next available row as will be moving stuff from sheet 1 to sheet 2 once a month

Thanks

VBA Code:
Dim mycell
For Each mycell In Selection.Columns(4).Cells
  If mycell.Value = "Closed" Then
    mycell.EntireRow.Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(3)(2)
    mycell.EntireRow.Delete
  End If
 
Delete the previous macro and place this macro in a regular module. It assumes that Sheet1 has headers in row 1 and that the data starts in row 2 with no blank rows.
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Sheets("Sheet2").UsedRange.Offset(1).ClearContents
    With Sheets("Sheet1")
        .Visible = True
        .Cells(1).CurrentRegion.AutoFilter 4, "Closed"
        .AutoFilter.Range.Offset(1).Copy Sheets("Sheet2").Cells(Sheets("Sheet2").Rows.Count, "A").End(xlUp).Offset(1)
        Application.DisplayAlerts = False
        .AutoFilter.Range.Offset(1).Delete
        Application.DisplayAlerts = True
        .Range("A1").AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Thanks but sometimes get Runtime error '91' Object variable or With block variable not set

Also forgot to mention the Data is in a Table and when finished the table goes down to over 1 million rows
 
Upvote 0
Please see Post #5 for instructions on how to post screenshots or to upload your file.
 
Upvote 0

Forum statistics

Threads
1,213,521
Messages
6,114,109
Members
448,548
Latest member
harryls

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