当我应用过滤器并运行宏时获取错误的行数

发布于 2024-12-10 06:32:41 字数 839 浏览 0 评论 0原文

我已经编写了一个宏,它工作正常,但我遇到了一些无法解决的问题。我无法发布代码,因为它有近 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

case 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 谁能告诉我为什么?

I have written a macro and it was working fine but i got some issue which im unable to resolve it.i could not post the code because its nearly 800 lines and The macro is about importing new codes which are unique, so I have run the macro without filtering any columns for the first time, it was working fine but then applied the auto filter for columns and filtered some rows and starting running the macro it was still working fine but when i run the macro , the next time the numer of rows counted is showing different

case 1

I have 35000 rows in my workbook that are old and run the macro working fine
imported 100 unique rows

case 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

case 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 

but it should be 35000 as total count could anyone tell me why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街九尾狐 2024-12-17 06:32:41

当我通过在新工作簿上进行越来越多的尝试时,我得到了自己问题的解决方案,我观察到的是,

rows= activesheet.Cells(Rows.count, 1).End(xlUp).Row

当未应用过滤器时,给出 35000

,但

rows= activesheet.Cells(Rows.count, 1).End(xlUp).Row

给出 24000,因为这是使用过滤器可以看到的最后一行,这就是它返回的内容。

我尝试过使用一个小的新工作簿,其中包含 10 个单元格中的一些随机值并进行计数,它给了我 10 作为答案,然后我对最后一次出现的值应用了过滤器 6 ,然后令人惊讶的是,它返回了该值作为 6 然后我明白了它在没有过滤器的情况下做了什么

     A
     1
     2
     3
     4
     5
     1
     6
     2
     3
     4

我得到了 10 作为计数现在我应用了值 1 的过滤器然后我得到了计数为 6,这就是最后一次出现 1 的地方。使用时要小心过滤器:)

我希望它能帮助其他看到这些帖子的人谢谢!

I got the solution to my own question when i tried it more and more by experimenting on new workbook, and what I observed is

rows= activesheet.Cells(Rows.count, 1).End(xlUp).Row

Gives 35000 when filters are not applied

but

rows= activesheet.Cells(Rows.count, 1).End(xlUp).Row

Gives 24000 because that is where the last row that can be seen using filter and that is what it returns.

I have tried it by taking a small new workbook with some random values in 10 cells and took the count, it gave me 10 as answer , then i applied filter for a value where its last occurence is 6 , then surprsingly , it returned the value as 6 then i understood what it was doing

     A
     1
     2
     3
     4
     5
     1
     6
     2
     3
     4

without filters i got 10 as count now i applied filters for value 1 then i got the count as 6, that is where the last occurence of 1 is.Be careful while using filters :)

I hope it helps some other people who sees these post Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文