Forum Discussion
chancelin
Nov 29, 2018Copper Contributor
Understand .Cells(.Rows.Count,“A”).End(xlUp).row
I was just wondering if you could help me better understand what .Cells(.Rows.Count,"A").End(xlUp).row does. I understand the portion before the .End part.
chancelin
Nov 30, 2018Copper Contributor
I understand better now.
This line means: selects (.Select) the last non-empty cell (.End) up (xlUp) from the last cell (& Rows.Count) of column A (Range ("A"))
So this command line behaves exactly as if you were in the last cell of column A (cell A1048576 for the 2007 version of Excel) and you press CTRL + up arrow.
Why go from the bottom of the sheet to the top and not the other way around? Quite simply, to avoid a selection error if it turned out that the array contains empty cells.
JKPieterse
Nov 30, 2018Silver Contributor
One reason to start from the bottom is if your column contains empty cells somewhere in the middle that is where the cursor would stop. Or if you are on the last filled cell and then hit control+down, you end up on row 1048576. Thus starting from row 1048576 and going up is a good idea.
- foreverlearnerDec 09, 2020Copper ContributorI see this is 2+ years old, please can I seek some clarifications
Please can I understand this way, the sequence of the execution is confusing me
Cells(.Rows.Count,“A”).End(xlUp).row
Please clear my understanding, Say cursor is at A1
Cells() is an object having the method End(), which is executed first so it goes to the end, while going to the end it calculates the rows ( or while traversing back to A1 ?) so now we have total rows for column A. Please can you explain me this and can I apply same logic to all functions.. - chancelinNov 30, 2018Copper Contributor
Very clear your comment.
Thank you Jan Karel Pieterse