ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   best way to get reference to all used cells (https://www.excelbanter.com/excel-programming/345357-best-way-get-reference-all-used-cells.html)

sugargenius

best way to get reference to all used cells
 
I was using the macro recorder to see how to use the range.sort
function. When I did, I got something like:

Range("A1:J235").Sort Key1:=Range("A1"), Order1:=xlAscending

I should always know the number of columns but the number of rows will
vary. What's the best in code of coming up the "A1:J235"?

Thanks,
Woody


Toppers

best way to get reference to all used cells
 
Hi,

lastrow=Cells(rows.count,"A").end(xlup).row

Range("A1:J" & lastrow).Sort Key1:=Range("A1"), Order1:=xlAscending

HTH

"sugargenius" wrote:

I was using the macro recorder to see how to use the range.sort
function. When I did, I got something like:

Range("A1:J235").Sort Key1:=Range("A1"), Order1:=xlAscending

I should always know the number of columns but the number of rows will
vary. What's the best in code of coming up the "A1:J235"?

Thanks,
Woody



sugargenius

best way to get reference to all used cells
 
thanks, I forgot you can concatenate strings and numbers without any
effort.



All times are GMT +1. The time now is 04:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com