[英]Excel VBA Wrong copy with Advanced Filter
Im trying to get a list of unique data through the Advanced Filter option in Excel. 我试图通过Excel中的“高级筛选器”选项获取唯一数据列表。 So, I recorded the macro I wanted to do and I got this as the code:
因此,我记录了想要执行的宏,并将其作为代码获取:
Sheets("Totaal").Range("A3:A65000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
"D2"), Unique:=True
This should be fine as far as I know because I did this a few times. 就我所知这应该没问题,因为我做了几次。 Problem is, with this one, he only copies the first element to the selected Range.
问题在于,他只将第一个元素复制到选定的范围。 (I tried with actually giving it a range but that didn't change anything).
(我尝试实际给它一个范围,但没有任何改变)。
So, only copying first element not the whole array. 因此,仅复制第一个元素而不复制整个数组。 If I do it manually it works.
如果我手动执行,它会起作用。
Stumbled onto this one, very interesting problem. 偶然发现了这个非常有趣的问题。 I created a test sheet to mimic yours that looked like:
我创建了一个模拟您的测试表,如下所示:
The following code dropped all of the unique entries into col D starting at row 2: 以下代码从第2行开始将所有唯一条目都放入col D:
Option Explicit
Sub Test()
Dim TotaalSheet As Worksheet
'set worksheet for easy reference
Set TotaalSheet = ThisWorkbook.Worksheets("Totaal")
'apply the advanced filter to get uniques
With TotaalSheet.Range("A3:A65000")
.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=TotaalSheet.Range("D2"), Unique:=True
End With
End Sub
Here are the results: 结果如下:
如果范围顶部的许多空单元格之一,则不会复制任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.