ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to get actual rows number in Excel using VBA? (https://www.excelbanter.com/excel-programming/358835-how-get-actual-rows-number-excel-using-vba.html)

[email protected]

How to get actual rows number in Excel using VBA?
 
Hi all,
Currently in my sheet1, the actual rows number is 20, that is,
only the first 20 rows have content in it.
But I use ActiveSheet.UsedRange.Rows.Count, and it gets 26, and
sometimes more.
Why?
How can I get the exactly 20?
Thanks.

michael


K Dales[_2_]

How to get actual rows number in Excel using VBA?
 
..UsedRange means the cells have been used, but does not mean that they are
necessarily still in use.

..CurrentRegion is good for finding the current range, as long as it is a
continuous rectangular range. So Range("A1").CurrentRegion.Rows.Count tells
how many rows are included in the region starting at A1.
--
- K Dales


" wrote:

Hi all,
Currently in my sheet1, the actual rows number is 20, that is,
only the first 20 rows have content in it.
But I use ActiveSheet.UsedRange.Rows.Count, and it gets 26, and
sometimes more.
Why?
How can I get the exactly 20?
Thanks.

michael



[email protected]

How to get actual rows number in Excel using VBA?
 
Got it!
Thank you very much, Dales!
It really helps!

michael


[email protected]

How to get actual rows number in Excel using VBA?
 
Got it!
Thank you very much, Dales!
It really helps!

michael


Patricia Shannon

How to get actual rows number in Excel using VBA?
 
In a situation where that doesn't work, delete the extra rows (and/or
columns) using Edit/Delete, than Save. Sometimes I have to do a Save As.
You can use Ctrl+End to see what Excel sees as the end of the used range.

" wrote:

Got it!
Thank you very much, Dales!
It really helps!

michael




All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com