I have been using these methods to count the number of rows in a sheet
getLastRowNum()
and
getPhysicalNumberOfRows()
They are working fine on two sheets of my workbook. But the third sheet containing 5 rows is returning 1 extra with both of the functions.
Sheet NumberofRows getLastRowNum() getPhysicalNumberOfRows()
1 9 9 10
2 56 56 57
3 5 4 5
What exactly is the difference in the working of the two functions and what can I do so I get reliable correct results?
getLastRowNum()
i.e Like an array it starts from 0 to n-1 if n is the number of rows.
getPhysicalNumberOfRows()
So for the number of rows 10, getLastRowNum() will be 9, as it start from 0.
This is one of the reason that getPhysicalNumberOfRows()
should be used instead of getLastRowNum()
because if the number of rows is 1 in the sheet, getLastRowNum()
would return 0
which cannot differentiate if there is 0 row or the only row is at position 0
while getPhysicalNumberOfRows()
would return 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With