Incorrect value when counting cells in different versions of Excel

守給你的承諾、 提交于 2019-12-01 17:48:16

When calculating such large numbers use .Countlarge property.

For example

Sub CellsCount()
    Dim l As Double
    l = ActiveSheet.Cells.CountLarge
    Debug.Print l
End Sub

Also never use Cells.Count or Cells.CountLarge without specifying the worksheet object. This is to ensure that we don't get incorrect count/error in compatibility mode. Similarly never use Rows.Count. Always use ws.Rows.Count. This is the most common error people make while trying to find the last row in excel. For example

This

lRow = ws.Range("A" & Rows.Count).End(xlUp).Row

and

lRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row

might not give you the same results always.

I would also recommend further reading of this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!