我已经编写了执行以下操作的代码:将自动过滤器应用于选定的sheet中的特定workbook将数据从标题以外的autofiltered range复制到另一个workbook这是代码: m = 2 For i = 1 To work_book.Worksheets.CountWith work_book.Sheets(i) If (.UsedRange.Rows.Count > 1) Then 'apply filters .UsedRange.AutoFilter field:=2, Criteria1:=array_of_account_numbers, Operator:=xlFilterValues .UsedRange.AutoFilter field:=1, Criteria1:=array_of_debit_or_credits, Operator:=xlFilterValues 'select only visible cells after autofilter is applied On Error Goto a m = destination_workbook.Sheets(1).UsedRange.Rows.Count + 1 Intersect(.UsedRange, .UsedRange.Offset(1)).SpecialCells(xlCellTypeVisible).Copy destination_workbook.Sheets(1).Range("A" & m) a: End If End With但是,宏持续复制一些垃圾。这意味着除了sheet之外,它还从每个rows前三个autofiltered range复制。我该如何解决这个问题?感谢您的帮助和解答。编辑这是工作表中数据的示例将过滤器应用于Criteria1( 60, 50)和Criteria2( 1470, 1450) (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 .UsedRange将获取源工作表中的所有数据,而不仅仅是自动过滤结果下方的数据。在Offset语句中使用的Intersect...Copy应该是要忽略的自动过滤结果上方的行数,而不是值1。如果您知道有多少标题行:numHeaderRows = 5For i = 1 To work_book.Worksheets.Count With work_book.Sheets(i) If (.UsedRange.Rows.Count > 1) Then 'apply auto-filters starting at the row directly above the start of the data. .UsedRange.Offset(numHeaderRows-1).AutoFilter field:=2, Criteria1:=array_of_account_numbers, Operator:=xlFilterValues .UsedRange.Offset(numHeaderRows-1).AutoFilter field:=1, Criteria1:=array_of_debit_or_credits, Operator:=xlFilterValues 'select only visible cells after autofilter is applied On Error Goto a m = destination_workbook.Sheets(1).UsedRange.Rows.Count + 1 Intersect(.UsedRange, .UsedRange.Offset(numHeaderRows)).SpecialCells(xlCellTypeVisible).Copy destination_workbook.Sheets(1).Range("A" & m) a: End If End WithNext (adsbygoogle = window.adsbygoogle || []).push({});
10-06 06:26