Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find bottom of Excel worksheet in VBA

Tags:

excel

vba

I'd like to select to the bottom of the worksheet, but not below what is used/stored. I might have 10,000 rows, but I certainly don't have 65,536. I won't know ahead of time how many rows.

In Excel itself (in recent versions, anyway; Excel 97 wasn't so kind) you can press Ctrl + End to be taken to the last row and column. I'd like the same functionality.

like image 822
Charles Avatar asked Nov 03 '10 22:11

Charles


2 Answers

The simplest way is to start at the bottom and work up to find the last row that contains something:
Range("a65536").end(xlup).row

like image 103
Charles Williams Avatar answered Oct 02 '22 06:10

Charles Williams


That's elementary:

Selection.End(xlDown).Select

(Found this out by pressing ctrl + end while recording a macro.)

like image 32
steinar Avatar answered Oct 02 '22 08:10

steinar