简体   繁体   English

Excel AdvanceFilter vba copyToRange 仅适用于最顶层的行

[英]Excel AdvanceFilter vba copyToRange only working for topmost Row

I have a sheet "RM" in a workbook, and another sheet "ST" in the same workbook.我在工作簿中有一个工作表“RM”,在同一个工作簿中有另一个工作表“ST”。 "RM" has Table2 and "ST" has Table 3 “RM”有表2,“ST”有表3

I use the following code to copy from RM to another sheet "Andy" refName is a Criteria in "Andy" and topRowName is the string "Andy!B1:M1"我使用以下代码从 RM 复制到另一个工作表“Andy” refName 是“Andy”中的条件,topRowName 是字符串“Andy!B1:M1”

Sheets("RM").Range("Table2[#All]").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range(refName), CopyToRange:=Range(topRowName), Unique:= _
        False

So far so good, everything works Now I want to copy from "ST" also to "Andy" but paste it a few rows below "topRowName" so that it doesn't overwrite so I do an offset到目前为止一切顺利,现在我想从“ST”复制到“Andy”,但将它粘贴到“topRowName”下面几行,这样它就不会被覆盖,所以我做了一个偏移量

Sheets("ST").Range("Table3[#All]").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range(refName), CopyToRange:=Range(topRowName).Offset(5), Unique:= _
        False

but it throws a 1004 Error "Extract Range has a missing or invalid field name"但它抛出一个 1004 错误“提取范围有一个缺失或无效的字段名称”

I tried to hardcode the values in the Range like this我试图像这样对 Range 中的值进行硬编码

Sheets("RM").Range("Table2[#All]").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range(refName), CopyToRange:=Range(Andy!B5:M5), Unique:= _
        False

But it still doesn't work.但它仍然不起作用。 Is it because there is a table in the paste location?是不是因为粘贴位置有表格? i tried to resize the table so that it doesn't clash with the new paste but its not helping.我试图调整表格的大小,使其不会与新粘贴发生冲突,但它没有帮助。 Any help appreciated任何帮助表示赞赏

Thanks all, I found the answer to the reason why this was happening.谢谢大家,我找到了发生这种情况的原因的答案。 I needed to clear out contents of the place I'm pasting to.我需要清除我粘贴到的地方的内容。 Apparently Excel doesn't like to copy contents to a range if there is something already present, particularly a ListObject like a table.显然,如果已经存在某些内容,尤其是像表格这样的 ListObject,Excel 不喜欢将内容复制到某个范围。 I assumed that it would just write on top of it.我以为它只会写在它上面。

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

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