调用remove duplicateates方法后,返回剩余值的计数

我有几个总结表,我试图自动化从一个到另一个的数据,代码目前都在工作,但是当我重新分配“ Tier2 ”命名范围我使用xlDownxlRight ,我感觉有点xlRight to。

我注意到,当你手动删除重复它给你一个msgbox剩余的数量。

有没有办法让删除重复方法也返回此属性的variables?

 'copies the first two columns of the Tier3 table Range([Tier3_anchor], WorksheetFunction.Index([Tier3], r, c)).Copy 'Pastes as values into the Tier2 table Range("Tier2_Anchor").PasteSpecial xlPasteValues 'removes duplicates from the Tier2 table Range([Tier2_anchor], Cells([Tier2_anchor].Row + r - 1, [Tier2_anchor].Column + 1)).RemoveDuplicates Columns:=2, Header:=xlNo 'This is a rough way to define the range of the Tier2 Table, there is a messagebox that returns remaining values after the remove duplicates, maybe able to capture that! Range("Tier2_anchor", Selection.End(xlDown)).Select Range(Selection, Selection.End(xlToRight)).Name = "Tier2" 

理想情况下,我会做这样的事情:

 Dim r As Integer Dim c As Integer r = UBound(A, 1) c = UBound(A, 2) 'pastes the array into the workbook with the top left corner starting on the named range "Tier3_Anchor" Range([Tier3_anchor], Cells(r + [Tier3_anchor].Row, c + [Tier3_anchor].Column)).Value = A 'renames the pasted data to Tier3 Range([Tier3_anchor], Cells([Tier3_anchor].Row + r, [Tier3_anchor].Column + c)).Name = "Tier3" 

你可以使用=COUNTA()工作表函数?

 'removes duplicates from the Tier2 table Range([Tier2_anchor], Cells([Tier2_anchor].Row + r - 1, [Tier2_anchor].Column + 1)).RemoveDuplicates Columns:=2, Header:=xlNo '// Use CountA to get remaining values: remainingValues = WorksheetFunction.CountA(Range([Tier2_anchor], Cells([Tier2_anchor].Row + r - 1, [Tier2_anchor].Column + 1))) MsgBox remainingValues & " values remaining"