简体   繁体   English

VBA:将非连续数据从一张纸复制到另一张纸

[英]VBA : Copying non-contiguous data from one sheet to another

I am working on a Worksheet where I have to filter out certain data, based on a particular date. 我正在工作表中,必须根据特定日期过滤掉某些数据。 After writing the code to filter the data using Range.AutoFilter , I wish to copy the visible data in the worksheet (which is non-contiguous) to another worksheet. 在编写代码以使用Range.AutoFilter过滤数据Range.AutoFilter ,我希望将工作表(不连续)中的可见数据复制到另一个工作表。 For this I am using 为此,我正在使用

With ThisWorkbook.Sheets("ImportDumpData")
    .Activate
    'frow variable counts the total number of rows in the sheet
    frow = .Range("A" & Rows.Count).End(xlUp).Row
    .Columns("U:U").Select
    Selection.AutoFilter
    .Range("U2:U" & frow).AutoFilter field:=1, Criteria1:=">" & ThisWorkbook.Sheets("Main").Range("C4"), Operator:=xlEnd
    .Range("A1:AF" & frow).SpecialCells(xlCellTypeVisible).Copy
End With

The error message pops up saying "Microsoft Office Excel cannot create or use the data range reference because it is too complex" for this .Range("A1:AF" & row).SpecialCells(xlCellTypeVisible).Copy line of code. 对于此.Range("A1:AF" & row).SpecialCells(xlCellTypeVisible).Copy代码行,错误消息弹出,提示“ Microsoft Office Excel无法创建或使用数据范围引用,因为它太复杂了”。 Please Suggest what can be done. 请建议可以做什么。

ActiveSheet.Range("$A$1:$F$518").AutoFilter Field:=4, Criteria1:=">" .Range("A:AF" & frow).SpecialCells(xlCellTypeVisible).Copy ActiveSheet.Range(“ $ A $ 1:$ F $ 518”)。AutoFilter字段:= 4,Criteria1:=“>” .Range(“ A:AF”&frow).SpecialCells(xlCellTypeVisible).Copy

use and this for your code 使用此代码

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

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