Page 1 of 1

Question for any VBA gurus

Posted: Thu Jan 20, 2005 11:35 am
by DPlotAdmin
There's a small problem with the DPlot Add-In that I'd like to address but I have reached the limit of my VBA knowledge. Most of the Add-In functions are designed to allow blank rows in the selection, which are simply ignored. So you can have 1000 rows of data followed by one or more blank rows followed by another 1000 rows of data, for example. This leads to an inefficiency when you make a selection by clicking column headers rather than dragging the cursor or using key combinations like Ctrl+Shift+End: the Add-In will look at all 65,536 rows on the sheet to see if there's any data there. If not for the "allow blank rows" feature I could simply stop at the first blank row. This doesn't cause any problems but is of course much slower than it needs to be. Excel obviously knows where the data stops or Ctrl+Shift+End would not work. So... in VBA what's the magic command to return the last used row?

Posted: Sun Jan 23, 2005 2:01 pm
by DPlotAdmin
Thanks to Bernard Liengme for the solution. If anyone else has a need, here it is:

Code: Select all

Dim Sel As Object
Dim LastUsedRow As Long

Set Sel = Selection
LastUsedRow = Sel.Find("*", Sel.Cells(1, 1), , , xlByRows, xlPrevious).row
Need a good Excel reference? Check out Bernard's work: http://www.stfx.ca/people/bliengme/, including "A Guide to Microsoft Excel for Scientists and Engineers" and "A Guide to Microsoft Excel for Business and Management"