存在数据的行数 [英] Row count where data exists

查看:93
本文介绍了存在数据的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很开心学习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.

这篇关于存在数据的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆