我想设置一个vba代码来过滤一张数据并将包含特定值的行切割到其他工作表。下面的代码片段用于其中一个过滤器。到目前为止,我正在努力调试这条线。Excel- VBA过滤器和移动结果
myRange.Offset(1).Resize(myRange.Rows.Count - 1).SpecialCells(xlVisible).Cut
我不断收到一个错误,我无法在多个部分上运行此操作。任何帮助将不胜感激。
Sub MoveButton()
Sheets("Sheet1").Activate
Set myRange = Range(Range("A1"), Range("Z" & Cells.Rows.Count).End(xlUp))
myRange.Resize(1).AutoFilter
myRange.AutoFilter Field:=13, Criteria1:="Closed"
myRange.Offset(1).Resize(myRange.Rows.Count - 1).SpecialCells(xlVisible).Cut
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Closed").Activate
ActiveSheet.Paste
Application.CutCopyMode = False
myRange.AutoFilter
End Sub
好吧,我这是我得到了使用记录宏。现在我只是不确定如何更改范围,以便它们自动选择所有已过滤的行并将它们复制并粘贴到下一张表中的下一行。
Sub MoveCancelled()
Sheets("Sheet1").Select
Rows("2:2").Select
Selection.AutoFilter
Selection.AutoFilter
Range("A2").Select
ActiveWindow.ScrollColumn = 7
ActiveSheet.Range("$A$2:$Z$20").AutoFilter Field:=13,Criteria1:="Closed"
Rows(3).Select ' Selecting the row to copy, but it could be more than just one row.
Selection.Copy
Sheets("Closed").Select
Rows(114).Select ' Selecting the paste location at the bottom of the next sheet.
ActiveSheet.Paste
End Sub
我发现这个主题,并最终废除了我所有的其他努力。
Autofilter Macro, then copy visible data ONLY and paste to next available row
该解决方案完美地工作。
先用原来的*宏录制*手动运行的锻炼.........然后检查由此产生的代码。 – 2015-02-10 17:17:01
不知道为什么你在过滤之前调整大小,你应该从标题行中过滤 – Davesexcel 2015-02-10 17:27:40
我试过使用宏记录器。我在上面的消息中添加了该代码。我不确定如何使范围自动选择所有过滤的行以剪切/复制或选择封闭工作表中的第一个空行。 – Tyler 2015-02-10 18:35:48