简体   繁体   English

VBA筛选器然后将行复制到新表吗? Excel 2007

[英]VBA filter then copy rows to a new sheet ? excel 2007

I need a way to copy rows with data what has been filter user auto-filter 我需要一种复制带有数据的行的方法,该方法一直是过滤器用户自动过滤器

My problem is i dont know why but when VBA copy's and paste data from a filter it makes both of the sheets row limit go all the way down to the max. 我的问题是我不知道为什么,但是当VBA复制并粘贴来自过滤器的数据时,它会使两个工作表的行限制一直下降到最大值。 Making my file size way bigger, and taking longer bc of the added size 使我的文件大小更大,并花费更长的BC

    Columns("B:B").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B:$B").AutoFilter Field:=1, Criteria1:="<>"
    Cells.Select
    Selection.Copy
    Sheets("Dump").Select
    Cells.Select
    ActiveSheet.Paste

Only thing i have found to deal with this is to 我发现要处理的唯一事情是

    Columns("B:B").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B:$B").AutoFilter Field:=1, Criteria1:="<>"

   'some how Copy all rows with data'

    Selection.Copy
    Sheets("Dump").Select
    Cells.Select
    ActiveSheet.Paste

I have tested out copying the rows without VBA and it did work without any errors but i dont know how to code VBA to do that so what im asking How to copy the rows that have been filter or if u happen to know away around the size limit problem that would be nice to 我已经测试了在不使用VBA的情况下复制行,并且确实可以正常工作而没有任何错误,但是我不知道如何对VBA进行编码,所以我在问如何复制已过滤的行,或者是否偶然知道周围的大小限制问题,对

Something like this should work for you: 这样的事情应该为您工作:

Sub tgr()

    Dim wsData As Worksheet
    Dim wsDest As Worksheet

    Set wsData = Sheets("Sheet1")
    Set wsDest = Sheets("Dump")

    With wsData.Range("B1", wsData.Cells(Rows.Count, "B").End(xlUp))
        .AutoFilter 1, "<>"
        .CurrentRegion.Copy wsDest.Range("A1")
        .AutoFilter
    End With

End Sub

I believe this will work in 2007 but I can only test it in 2013 (and it worked). 我相信这会在2007年生效,但我只能在2013年对其进行测试(并且有效)。 Try to use the paste special "SkipBlanks" option: 尝试使用粘贴特殊的“ SkipBlanks”选项:

ActiveSheet.Columns("B:B").AutoFilter
ActiveSheet.Range("$B:$B").AutoFilter Field:=1, Criteria1:="<>"
ActiveSheet.Columns("B:B").Copy
Sheets("Dump").Columns("B:B").PasteSpecial SkipBlanks:=True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM