Question for any VBA gurus

VBA and general Excel Q&A and examples
Post Reply
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Question for any VBA gurus

Post 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?
Visualize Your Data
support@dplot.com
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post 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"
Visualize Your Data
support@dplot.com
Post Reply