存在数据的行数

编程入门 行业动态 更新时间:2024-10-28 00:24:28
本文介绍了存在数据的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我很开心学习VBA,并且想知道有人可以帮助我使用我需要的代码来计算数据的总数。我想要能够在不同数量的数据行的多个工作表上使用这个。

更具体来说,我无法弄清楚通用代码会计算从 A1 - A100或A1- A300。

现在我正在尝试使用这样的东西,但它不起作用。

i = ActiveWorkbook.Worksheets(Sheet1)。Range(A2,Range(A2)。End(xlDown ))。Rows.Count

请帮助!

谢谢

解决方案

如果你需要VBA,你可以这样做一些快速的事情:

Sub Test() With ActiveSheet lastRow = .Cells(.Rows.Count,A)。End(xlUp)。行 MsgBox lastRow 结束结束子

这将打印最后一行的数据,其中包含数据。显然,如果您将其用于其他目的,则不需要MsgBox,但lastRow将成为该值。

I am new to learning VBA and was wondering if someone could help me with the code I need to count the total number of rows that I have with data in them. I want to be able to use this on multiple sheets with different amounts of data rows.

More specifically I cannot figure out generic code that will count the number of rows from A1 - A100 or A1- A300.

Right now I am trying to use something like this, but it does not work.

i = ActiveWorkbook.Worksheets("Sheet1").Range("A2 , Range("A2").End(xlDown)).Rows.Count

Please help!

Thanks

解决方案

If you need VBA, you could do something quick like this:

Sub Test() With ActiveSheet lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row MsgBox lastRow End With End Sub

This will print the number of the last row with data in it. Obviously don't need MsgBox in there if you're using it for some other purpose, but lastRow will become that value nonetheless.

更多推荐

存在数据的行数

本文发布于:2023-07-22 12:38:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1187581.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:行数   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!