AutoFilter with Selection.cut

RuthandAndy

New Member
Joined
Jul 18, 2011
Messages
27
I am trying to cut the data resulting from AutoFilter and paste it into another worksheet. I can successfully copy data, but when I attempt cut, I end up cutting all data from the first worksheet and pasting it into the second worksheet. Here is the code that works for .copy, LastRow is a variable.

Range("A4", "Ap" & LastRow).Select
with Sheets("production status")
.AutoFilterMode = False
.Range("A3", "Ap" & LastRow).AutoFilter
.Range("A3", "Ap" & LastRow).AutoFilter Field:=1, Criteria1 ="Z"
end with

Selection.Copy

When I try to change the last line to Selection.Cut is when the filter seems to quit working and all the data gets cut.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try...

Code:
[FONT=Verdana][COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=darkblue]Sub[/COLOR] test()[/FONT]
 
[FONT=Verdana] [COLOR=darkblue]Dim[/COLOR] Rng [COLOR=darkblue]As[/COLOR] Range[/FONT]
[FONT=Verdana] [COLOR=darkblue]Dim[/COLOR] LastRow [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR][/FONT]
 
[FONT=Verdana] [COLOR=darkblue]With[/COLOR] Sheets("Production Status")[/FONT]
[FONT=Verdana]     .AutoFilterMode = [COLOR=darkblue]False[/COLOR][/FONT]
[FONT=Verdana]     LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row[/FONT]
[FONT=Verdana]     [COLOR=darkblue]With[/COLOR] Range("A3:AP" & LastRow)[/FONT]
[FONT=Verdana]         .AutoFilter field:=1, Criteria1:="Z"[/FONT]
[FONT=Verdana]         [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR][/FONT]
[FONT=Verdana]         [COLOR=darkblue]Set[/COLOR] Rng = .Resize(.Rows.Count - 1).Offset(1, 0).SpecialCells(xlCellTypeVisible)[/FONT]
[FONT=Verdana]         [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0[/FONT]
[FONT=Verdana]         [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] Rng [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR][/FONT]
[FONT=Verdana]             .Copy Destination:=Sheets("Sheet2").Range("A1")[/FONT]
[FONT=Verdana]             Rng.EntireRow.Delete[/FONT]
[FONT=Verdana]         [COLOR=darkblue]Else[/COLOR][/FONT]
[FONT=Verdana]             MsgBox "No records found...", vbExclamation[/FONT]
[FONT=Verdana]         [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR][/FONT]
[FONT=Verdana]     [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR][/FONT]
[FONT=Verdana]     .AutoFilterMode = [COLOR=darkblue]False[/COLOR][/FONT]
[FONT=Verdana] [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]
 
Upvote 0

Forum statistics

Threads
1,223,431
Messages
6,172,079
Members
452,444
Latest member
ShaImran193

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