我写了一个宏,它工作正常,但我遇到了一些问题,我无法解决它。我无法发布代码,因为它近800行和宏是关于导入新的代码,这是唯一的,所以我已经运行宏而没有第一次过滤任何列,它工作正常但后来应用了列的自动过滤器并过滤了一些行并开始运行宏它仍然工作正常但是当我运行宏时,下一次计算的行的数量显示不同
案例1
I have 35000 rows in my workbook that are old and run the macro working fine
imported 100 unique rows
案例2
i have closed and reopened the file and
now applied filters to the sheet and the last row that i can see is 24000
but rows count is still 35000 in vba thats what i wanted , then run macro
it gave 100 and working fine
案例3
now i have reopened my workbook and run the macro as normal then applied filters
for the sheet that has both newly imported and old entries now it gives 24000
as rows count that is where the last filtered row is
但它应该是35000,总计数可以告诉我为什么?
答案 0 :(得分:0)
当我通过试验新工作簿来越来越多地尝试它时,我得到了我自己的问题的解决方案,我观察到的是
rows= activesheet.Cells(Rows.count, 1).End(xlUp).Row
未应用过滤器时提供35000
但
rows= activesheet.Cells(Rows.count, 1).End(xlUp).Row
给出24000,因为这是使用过滤器可以看到的最后一行,也就是返回的行。
我试过一个小的新工作簿,在10个单元格中有一些随机值并计算,它给了我10作为答案,然后我应用过滤器得到一个值,其最后一次出现是6,然后是surprsingly,它返回值6然后我明白它在做什么
A
1
2
3
4
5
1
6
2
3
4
没有过滤器我得到10作为计数现在我应用过滤器值1然后我得到计数为6,这是最后一次出现1的地方。使用过滤器时要小心:)
我希望它可以帮助其他人看到这些帖子谢谢!