I have a Excel worksheet that has a button.
When I call the usedRange() function, the range it returns includes the button part.
Is there anyway I can just get actual used range that contains data?
I have a Excel worksheet that has a button.
When I call the usedRange() function, the range it returns includes the button part.
Is there anyway I can just get actual used range that contains data?
Here's a pair of functions to return the last row and col of a worksheet, based on Reafidy's solution above.
What sort of button, neither a Forms Control nor an ActiveX control should affect the used range.
It is a known problem that excel does not keep track of the used range very well. Any reference to the used range via VBA will reset the value to the current used range. So try running this sub procedure:
Failing that you may well have some formatting hanging round. Try clearing/deleting all the cells after your last row.
Regarding the above also see:
Excel Developer Tip
Another method to find the last used cell:
Change the search direction to find the first used cell.
Readify made a very complete answer. Yet, I wanted to add the
End
statement, you can use:Find the last used cell, before a blank in a Column:
Find the very last used cell in a Column:
Find the last cell, before a blank in a Row:
Find the very last used cell in a Row:
See here for more information (and the explanation why
xlCellTypeLastCell
is not very reliable).I use the following vba code to determine the entire used rows range for the worksheet to then shorten the selected range of a column:
Also works the other way around: